I'm currently developing a webapp in spring boot with thymeleaf as templating engine. Im coming from the PHP/NodeJS(SailsJS)-World so iteratively designing html pages with css was never a problem. I could make some minor changes in the html/css code, go back to the browser and hit refresh to see the change.
I do this a lot in PHP/NodeJS. It's countless forward and backward until I get the design I was shooting for.
Now I want to do this in SpringBoot but whenever I change the HTML/CSS code (static or template) an refresh in the browser, there is no change. I have to restart the application to see the change and that needs at last 4 seconds and up to 14 seconds in some situations. That's completely unacceptable as I have to go back and forth so often that this would massively decrease my productivity but I wanted to use SpringBoot in the first place to increase my productivty.
I googled a bit and some people seem to advise the "Spring Devtools". I included this dependency but still no change. Even if it would work, it would just auto-restart the app which doesn't solve my problem. There must be a way to tell Spring not to cache my static and dynamic html content but to deploy/process them directly from their place within the project. I mean in other Frameworks like PHP-Zend or NodeJS-SailsJS this is the absolute standard.
In PHP-Zend for example there is a cache but it is disabled by default and should only be enabled for production environments by the developer. Is there a way to let Spring behave in similar manners?
And if not, how do Spring developers design their html/css efficiently?
Thanks in advance
Be warned! The following solution is something you only want in your LOCAL application.properties. You do not want to add these lines to your QA, PROD, ... application.properties files.
In your LOCAL application.properties you need to add the following 3 lines
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=file:./src/main/resources/templates/
spring.resources.static-locations=file:./src/main/resources/static/
You will obviously need to adjust the paths to your folder structure and restart the server.
Related
I'm searching for a hint/solution to generate one Template-Webapp with a custim design and then all my other Webapps should take the design from the Template-Webapp. Is that possible? The Idea behind is, that we I have multiple Webapps for Projects, but the Layout,... is the same on all Project. And when changing the Template-Webapp, all other Webapps are changed without changing the source-code in all Webapps.
I've got a running Webapp with my design(Template-Webapp). All is runing on a Tomcat 7. In another Webapp, I tried to use the template-file from the Template-Webapp, but I can't get it running. Perhaps its not possible to navigate through the webapp-folders on Tomcat? It's showing "invalid path"-failure. But, the path is correct. With selecting the path, I can easy access the template-file.
Does anybody had the same problem or knows how to solve it ?
Thanks for every help, even if it's small
You should look into breaking your front-end pieces up.
It ends up being like moving magnets around on a refrigerator. Except the magnets are components of your template!
It is called templating with composite values.
My Related Answer:
How does JSF render more than one JSP pages into 1 single view?
Documentation:
JSF 2 fu: Templating and composite components
Core J2EE Patterns - Composite View - Oracle
Hope that helps!
Take a look on some webresources how to work with templating (JSF > 2.0) and contracts (JSF > 2.2).
http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/
http://hantsy.blogspot.de/2013/08/jsf-22-theme.html
The best way to share one template across many projects is to bundle the contract including all recources into one *.jar
As far as i know, the template/contract/whatever should be in the right directorys, thus within the same project at least included as jar.
We are developing a project with spring framework.
we are using a tomcat cluster and in order to do some really advanced integration tests we added some controllers to the web app that are allowing some risky stuff that must not reach the production.
What we learned is that in order to do so we can use spring profiles and annotate the risky controllers as with the
#profile("Staging")
This annotation makes sure the bean will be created only when the active profile is "Staging".
Call me paranoid but this risky code now resides on our svn and is part of the project code.
It seems that the slieghtest mistake can lead to this code be part of production and allowing risky actions for exploiters.
moreover if some programmer forgets to annotate the code will reach the production for sure.
we all make mistakes.
Is there any mitigation for this issue?
I'll call you a bit paranoid. (wink) Hopefully you also have integration tests in your application, and they usually set up some of the environment - if they ever were to run in a production environment, they would probably screw up your database, send messages to other systems, etc.
You you don't worry about that. Why? Maybe you can use the answer to that to answer how you should package those risky pieces of code.
My suggestion: keep all the risky code in a single module (if you are using a multi-module build). Don't include this module in the production build (you can use maven profiles for that)
Or.. let the code check for itself whether it is allowed to run. Perhaps it can check for the presence of a certain file on the file system that you only create in your test environment.
It depends really on what you worry about.
But it is good to think about it. I know stories where load testing resulted in many orders being placed in an actual (external) order processing system.
The mistake you are speaking about is adding staging to list of active profiles. Yes, it is easy to do this. However it is easy to remove files from file system format the hard disk and turn the electricity off. So, your question really sounds as a kind of paranoia... :)
I think that the problem is not in Spring profiles but in your development methodology. If you are not sure in some code it should not be in production at all. How to achieve this? Move from svn to git. And start using branches. Each task is a branch. Without exceptions. Each task must be tested. So you can deploy every branch you want to staging, test it and when you are sure that the code is ok merge/rebase it to master. Master should be tested as well, and then can be deployed to production.
In this case you do not need profile "staging".
I have a third party application which has lot of servlets and jsp. I wanted to debug that by putting breakpoints on my local jboss server. How do I know that, for a particular request, the request is being processed by particular java classes and jsp, so that I can put breakpoints in the right files? I am thinking of going through the code, before setting the breakpoints, to know where to put them. But I feel this is not an efficient way to do it (as it is a very big application). Can you please suggest if there is any better way to do this?
Thanks in advance.
The web.xml file contains servlet-mapping elements indicating which servlets are mapped to which URLs. So if you know the URL, you should easily find the corresponding servlet. Now you can read the servlet code to see which other classes are involved.
I think fastest way for debugging applications like this, is profiling application for specific usecase, in this way you can understand which classes used for this scenario and after finding classes, you can debug these classes.
for profiling application there are lots of tools.
commercial: Yourkit, JProfiler, JProbe
open source:VisualVM, Javacalltracer (create run-time sequence diagram)
before asking, please understand that my english is not good.
I'm using Class.forName(...) class in a servlet programming. when I access the servlet, I get a row of detailed controller information from Database indicating which controller to use.
This is Class.forName(...) I coded:
Class c = Class.forName(row.getControllerInfo);
c.newInstance();
This works fine, but there's a problem, i'm using Eclipse. The problem is that when I modified the Controller file, the changed contents were not applied to the server.,,.
Probably the easiest way is not to support dynamic loading. Much better to achieve something like dynamic update by supporting multiple servers. For development, you could get around redeploy delays by using JRebel (there might be others).
If you really do want dynamic loading of classes then the answer is "class loaders". I suggest having a look at those, and come back with any specific questions.
If I understood your problem true,
When you change any file of your project, you must deploy your project to server. If you use server from eclipse, republish may solve your problem.
have you tried clean - re-built and then deploying your application?
I'm playing with a GWT/GAE project which will have three different "pages", although it is not really pages in a GWT sense. The top views (one for each page) will have completely different layouts, but some of the widgets will be shared.
One of the pages is the main page which is loaded by the default url (http://www.site.com), but the other two needs additional URL information to differentiate the page type. They also need a name parameter, (like http://www.site.com/project/project-name. There are at least two solutions to this that I'm aware of.
Use GWT history mechanism and let page type and parameters (such as project name) be part of the history token.
Use servlets with url-mapping patterns (like /project/*)
The first choice might seem obvious at first, but it has several drawbacks. First, a user should be able to easily remember and type URL directly to a project. It is hard to produce a human friendly URL with history tokens. Second, I'm using gwt-presenter and this approach would mean that we need to support subplaces in one token, which I'd rather avoid. Third, a user will typically stay at one page, so it makes more sense that the page information is part of the "static" URL.
Using servlets solves all these problems, but also creates other ones.
So my first questions is, what is the best solution here?
If I would go for the servlet solution, new questions pop up.
It might make sense to split the GWT app into three separate modules, each with an entry point. Each servlet that is mapped to a certain page would then simply forward the request to the GWT module that handles that page. Since a user typically stays at one page, the browser only needs to load the js for that page. Based on what I've read, this solution is not really recommended.
I could also stick with one module, but then GWT needs to find out which page it should display. It could either query the server or parse the URL itself.
If I stick with one GWT module, I need to keep the page information stored on server side. Naturally I thought about sessions, but I'm not sure if its a good idea to mix page information with user data. A session usually lives between user login and logout, but in this case it would need different behavior. Would it be bad practise to handle this via sessions?
The one GWT module + servlet solution also leads to another problem. If a user goes from a project page to the main page, how will GWT know that this has happened? The app will not be reloaded, so it will be treated as a simple state change. It seems rather ineffecient to have to check page info for every state change.
Anyone care to guide me out of the foggy darkness that surrounds me? :-)
I'd go with History tokens. It's the standard way of handling such situations. I don't understand though, what you mean by "It is hard to produce a human friendly URL with history tokens" - they seem pretty human friendly to me :) And if you use servlets for handling urls, I think that would cause the whole page to be reloaded - something which I think you'd rather want to avoid.
Second, I'm using gwt-presenter and
this approach would mean that we need
to support subplaces in one token,
which I'd rather avoid.
If you are not satisfied with gwt-presenter (like I was :)), roll out your own classes to help with MVP - it's really easy (you can start from scratch or modify the gwt-presenter classes) and you'll get a solution suited to your needs. I did precisely that, because gwt-presenter seemed to "complicated"/complex to me - to generic, when all I needed was a subset of what it offered (or try to offer).
As for the multiple modules idea - it's a good one, but I'd recommend using Code Splitting - this type of situation (pages/apps that can be divided into "standalone" modules/blocks) is just what it's meant to be used for, plus you bootstrap your application only once, so no extra code downloaded when switching between pages. Plus, it should be easier to share state that way (via event bus, for example).
Based on what you have posted I presume you come from building websites using a server side framework: JSP, JSF, Wicket, PHP or similar. GWT is not the solution for building page-based navigational websites, like you would with the aforementioned frameworks. With GWT, you load a webapp in the browser and stay there. Handle user events, talk with the server and update widgets; using gwt-presenter is a good thing here as you are forced to think about separation of controller logic and view state.
You can really exploit all features of GWT to build a high-performance app-in-the-browser, but it is definately not meant for building websites (using hyperlinked pages that transfer request parameters via the server session).
This is by far the most widely asked question about GWT here # StackOverflow :)
"How do I define pages and navigation between them in GWT?" Short answer: "You don't."
Use Wicket instead, it runs on the App Engine just fine and enables you to define page bookmarks and all stuff you mentioned above. Look here: http://stronglytypedblog.blogspot.com/2009/04/wicket-on-google-app-engine.html