I've created a simple Spring Boot Web Application in intelliJ. I've placed a simple .jsp file in the /src/main/resources/templates/ folder which contains some basic HTML.
I'm trying to return this in a controller but I'm getting this error;
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Sep 09 10:37:46 BST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
I'm assuming that Spring is unable to find the .jsp file, but there's no other errors appearing in the console to give me any further information.
Here's my simple controller;
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping("")
public ModelAndView index() {
return new ModelAndView("test");
}
}
I've included the following in my application.properties file;
spring.mvc.view.prefix = /templates/
spring.mvc.view.suffix = .jsp
My POM file includes the following dependencies;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
I'm using Spring Boot with embedded tomcat.
I've tried changing the path to the views inside application.properties to; classpath:/templates/ but that also didn't make any difference.
Finally, here is the structure of my project;
When running the application, I'm just using the 'Run' option in IntelliJ.
jsp file in the /src/main/resources/templates/ folder which contains some basic HTML.
Undertow will not support JSP if used as an Embedded Servlet Container. If deploying in a web container, our @SpringBootApplication annotated class should extend SpringBootServletInitializer and provide necessary configuration options. We can't override the default /error page with JSP.
From the main menu, select Run | Edit Configurations. Select the necessary Spring Boot run configuration to open its settings. Click Modify options. In the list that opens, point to On 'Update' action.
3 and all you have to do is go to "Settings > Editor > File Types". Under "Recognized File Types", click on HTML, then under "Registered Patterns" add *. jsp .. Nothing else is required.
Setting working directory helped me --- by default, it was empty.
Edit your configuration for Spring boot application in Idea.
Set up the working directory, like it's done on a screenshot below:
I have recently experienced the same situation with below dependency:-
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
If I change the "scope" to "default", run the application with Intellij, it works fine.
But if I want to keep the "scope" as "provided", I have to use the command line (terminal) and execute the following:-
mvn clean spring-boot:run
It works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With