Issue with using JSP template in multi module Spring Boot Project

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
------ 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).

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

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.

1 Like

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.

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.

Try the following

  • location jsp

  • location static resources

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