JavaSpringBootWebStarter视图位置
我尝试制作一个简单的Spring Boot web应用程序:
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>
主要类别:
@ComponentScan(basePackages={"controller"})
@Import(MvcConfig.class)
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
控制员:
@Controller
@RequestMapping("/home")
public class HomeController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hello";
}
@RequestMapping("/helloView")
public String helloView(){
return "homeView";
}
}
也在{
src
-main
-resources
applicaion.properties
-webapp
-WEB-INF
-jsp
-homeView.jsp
在应用中。我得到的财产:
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
rest端点/home/hello
可以工作,但另一个端点无法打开jsp。
在我得到的日志中
Looking up handler method for path /WEB-INF/jsp/homeView.jsp
Did not find handler method for [/WEB-INF/jsp/homeView.jsp]
我应该将视图放在哪里,以便应用程序可以找到它们
# 1 楼答案
感谢geoand的回答,我补充道
去了pom,它成功了