0

I created a spring boot application with initialiser.

The spring boot version is 2.1.3. release.

The issue is that I want to include JSP in the boot app but there is no webapp folder generated. I had selected Spring MVC while generating the app.

I created a jsp in src/main/resources/templates folder and tried to load the same with various configuration in application.properties like,

spring.mvc.view.prefix=/WEB-INF/templates/
spring.mvc.view.suffix=.jsp

spring.mvc.view.prefix=/WEB-INF/classes/templates/
spring.mvc.view.suffix=.jsp 

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

But none of them are working. I gets 404 whitelabel error.

I tried to check spring references but I couldn't find any changelog related to template folder.

I also tried adding below dependencies in pom.xml

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <scope>provided</scope>
    </dependency>
Nimesh
  • 794
  • 3
  • 8
  • 18

1 Answers1

0

Try to change the Following in tomcat-embed-jasper

Remove <scope>provided</scope> OR change the scope to compile <scope>compile</scope>

JSP Limitation

When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

  • With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.
  • Undertow does not support JSPs.
  • Creating a custom error.jsp page does not override the default view
    for error handling. Custom error pages should be used instead.

Scope

compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

runtime This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

JSP Limitations Spring Boot JSP 404

Romil Patel
  • 12,879
  • 7
  • 47
  • 76