Spring boot can not find jsp views
Solution 1
I checkout-ed your code from github
and managed to deploy into embedded Tomcat 8.0.3
and standalone Tomcat 8.0.x
.
I will just go through the steps for embedded Tomcat
instead of Jetty
(as I have not figured out the Jetty
configuration fully yet).
There are two things that you could do
- Copy your webapps into the following location without the s, e.g.
/dvdexchange-spring-boot/src/main/webapp
-
UPDATE:
IngeniousTom,
I was not able to make it work in embedded Jetty
, the furthest point I could reach after struggling to add numerous Maven
Jetty
jar libraries as shown below
This is actually a known issue and I do not see how this can be solved without any hackish way.
If you read in the github
link, there is numerous discussion between Spring-Boot and Jetty camps.
The bottom line of the discussion is that Spring-Boot
does not support yet Jsp
in embedded Jetty
as their standard but have plans in future.
My recommendation is not to use Jsp
or use other than Jetty
as your embedded container.
Solution 2
JSPs in executable JARs are not officially supported by Spring Boot, this is one of the known JSP limitations. Also, Spring Boot supports JSPs in embedded Jetty as of 1.4.0.RC1, not before.
Right now you can solve this by using Spring Boot 1.4+ and packaging your application as an executable WAR. You'll be able to deploy your app as a regular WAR, run it with java -jar app.war
and have a nice development experience - all of this with standard JSPs.
Maybe you'll find tricks to work around those limitations, but keep in mind that those often rely on container-specific behavior that aren't supported by the servlet spec. So at best, this behavior will be inconsistent between containers - and it's certainly possible that containers may change their behavior at any time.
If you really want to package your app as an executable JAR, then the best approach is not to use JSPs and pick a proper template engine.
IngeniousTom
I'am highly interested in Game Developement, Programming and music. I love to learn something new in IT sphere as much as making games and gaming. Feel free to message me if your interests matches mine - perhaps we will be good friends.
Updated on June 11, 2022Comments
-
IngeniousTom about 2 years
Helo everyone! I completed my Spring based web app and then started to rebuild it to Spring boot because it gives me ability to use embedded jetty. At the moment I got some problem - Spring boot can not find (resolve) jsp views. So when I run my app - I get the error in browser:
Here is my web app on github - so you can just look at files and find the reason.
Help me please!
P.S. Yes I used @ResourceImport because I don't know how to rewrite the existing spring configuration xml files to java-based config files but you may show me HOW to do that in your answer.
P.P.S. And for some reason the target directory does not contain WEB-INF and it's content folders after compiling. May be this is the reason but I don,t know how to solve it!
-
IngeniousTom almost 8 yearsSo does it mean that if I want to use jsp in my web app then I can't use embedded jetty? I really need them both in my project. Could you give any solution?
-
Brian Clozel almost 8 yearsYou can package your project as a WAR and even run it as an executable WAR. See spring boot reference doc
-
IngeniousTom almost 8 yearsThank you for detailed answer but does 1st way allow me to use embedded jetty with spring boot?
-
IngeniousTom almost 8 yearsThank you but jetty is nessesary for my project.
-
IngeniousTom almost 8 yearsJAR is not nessesary, I can go with WAR. But what should I do with my viewResolver configuration and folder stucture? Have a look at my repository on github to answer (there is the link in my question). Thanks in advance!
-
Brian Clozel almost 8 yearsTake a look at this example: github.com/spring-projects/spring-boot/tree/master/…
-
IngeniousTom almost 8 yearsI did how you said but it does not work. Have a look at my dispatcherServlet.xml should I change something there? (The github link is in my question)
-
IngeniousTom almost 8 yearsI downloaded that source code and opened in my IntelliJ IDEA. When I run it I get error
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [sample.jetty.jsp.SampleJettyJspApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
-
IngeniousTom almost 8 yearsLet us continue this discussion in chat.
-
granadaCoder almost 6 yearsHere is another point I think. But it is the opposite of what you discovered? from docs.spring.io/spring-boot/docs/current/reference/html/… "Do not use the src/main/webapp directory if your application is packaged as a jar. Although this directory is a common standard, it works only with war packaging, and it is silently ignored by most build tools if you generate a jar."