Spring boot, JSP file as view does not load when IntellJ starts

I created a simple Spring Boot web application in intelliJ. I put a simple .jsp file in the / src / main / resources / templates / folder, which contains the basic HTML code.

I try to return this in the controller, but I get 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 assume Spring cannot find the .jsp file, but there were no other errors in the console that could give me more information.

Here is my simple controller;

@Controller
@RequestMapping("/test")
public class TestController {

    @RequestMapping("")
    public ModelAndView index() {
        return new ModelAndView("test");
    }

}

I 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 am using Spring Boot with a built-in cat.

I tried changing the path to the views inside application.properties; classpath: / templates /, but that also didn't make any difference.

Finally, here is the structure of my project;

Project file structure

"" IntelliJ.

+8
6

: -

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

" " " ", Intellij, .

" " "", () : -

mvn clean spring-boot:run

.

+5

tomcat-embed-jasper ( "" ), ... spring boot 1.5.2 idea 2017.1. - IDEA, maven gradle. , .

, spring IDEA - . , IDEA , Spring.

+4

IntelliJ Spring 27.1.7. :

IntelliJ IDEA - , . IDE , Maven Gradle . Spring . , IDE, . , classpath: classpath*:/templates/.

+3

IntelliJ:

webapp/WEB-INF/jsps/- , jsps.

:

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

application.properties, InternalResourceViewResolver bean .

:

@Configuration
@EnableWebMvc
public class WebMvcConfig {

    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsps/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}

- IntelliJ

+2

. 2 .

1) Maven "war", "webapp" war. 'jar', 'webapp'.

2) Starting spring loading of the main class from IntelliJ does not work. Launch the application from the command line using the command: 'mvn spring-boot: run'

0
source

At IntelliJ, YOU CANNOT put the provided under tomcat-embed-jasper!

<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
</dependency>
0
source

Source: https://habr.com/ru/post/1654113/


All Articles