I tried to make a simple Spring Boot web application:
POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Main class:
@ComponentScan(basePackages={"controller"})
@Import(MvcConfig.class)
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
the controller:
@Controller
@RequestMapping("/home")
public class HomeController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hello";
}
@RequestMapping("/helloView")
public String helloView(){
return "homeView";
}
}
Also under src/main
i got
src
-main
-resources
applicaion.properties
-webapp
-WEB-INF
-jsp
-homeView.jsp
In application.properties I got:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
The rest endpoint /home/hello
works, but the other one can't open the jsp.
In the log i got
Looking up handler method for path /WEB-INF/jsp/homeView.jsp
Did not find handler method for [/WEB-INF/jsp/homeView.jsp]
Where should I put the views so the app can find them?
Starter of Spring web uses Spring MVC, REST and Tomcat as a default embedded server. The single spring-boot-starter-web dependency transitively pulls in all dependencies related to web development. It also reduces the build dependency count.
In the index. html file we have a link that invokes a response from the web application. The file is located in the src/main/resources/static directory, which is a default directory where Spring looks for static content.
Auto-configuration for Jackson is provided and Jackson is part of spring-boot-starter-json . When Jackson is on the classpath an ObjectMapper bean is automatically configured. Several configuration properties are provided for customizing the configuration of the ObjectMapper .
jsp . The ResourceBundleViewResolver inspects the ResourceBundle identified by the basename, and for each view it is supposed to resolve, it uses the value of the property [viewname].
Thanks to geoand's answer I added
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
to the pom and it worked.
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