Spring boot can not find jsp views

后端 未结 3 569
攒了一身酷
攒了一身酷 2020-12-18 03:42

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

相关标签:
3条回答
  • 2020-12-18 04:31

    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.

    0 讨论(0)
  • 2020-12-18 04:42

    If you want to do a jar-Deployment you cannot use the wepapp folder.

    1. Put your JSPs to src/main/resources/META-INF/resources/jsp
    2. Put these lines to your application.properties file:

      spring.mvc.view.prefix=/jsp/
      spring.mvc.view.suffix=.jsp
      

    You can have a look to this project. It also uses Spring-Boot, a jar-Deployment and JSPs: https://github.com/synyx/urlaubsverwaltung

    0 讨论(0)
  • 2020-12-18 04:44

    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

    1. Copy your webapps into the following location without the s, e.g. /dvdexchange-spring-boot/src/main/webapp

    1. Modify slightly your pom.xml, e.g. below

    2. The final outcome as below

    -

    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.

    0 讨论(0)
提交回复
热议问题