Issue with using JSP template in multi module Spring Boot Project


(Bob) #1

I am trying to configure Gradle to use Spring Boot with multi modules, this is my structure:

------ Parent
------------ scr/main/java/config —> Config Files
------------ scr/main/java/App —> Spring Boot Application
------------ application.properties
------ Web
------------ scr/main/java/resources/WEB-INF —> Template Files
------ Core
------ Services

When I start my application, I see my mapping working and it seems that everything works well but the problem is that Spring does not find my templates:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/welcome.jsp

What is wrong with my config? Where should I put my template files?


(James Justinic) #2

Your templates files are currently in src/main/resources, which is for resources on the classpath. You want your WEB-INF folders in the webapp source directory (src/main/webapp).

Note that you will need to build an executable WAR, not an executable JAR for JSPs to work properly.


(Bob) #3

I moved the template files and WEB-INF folders in src/main/webapp folder and added apply plugin: 'war' in the build.gradle file of Web module. Still getting the same error.


(James Justinic) #4

Spring still needs to be configured correctly for your views. As long as you see your templates in WEB-INF as opposed to WEB-INF/classes/WEB-INF in the WAR, the Gradle part is as expected.


(leppk) #5

Try the following

  • location jsp
    src/main/resources/META-INF/resources/WEB-INF/jsp

  • location static resources
    src/main/resources/static

  • write on application.yml
    spring:
    mvc:
    view:
    prefix: "/WEB-INF/jsp/"
    suffix: “.jsp”