【问题标题】:Spring Boot Web starter views locationSpring Boot Web starter 视图位置
【发布时间】:2014-05-09 00:00:55
【问题描述】:

我尝试制作一个简单的 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我也得到了

src
   -main
       -resources
            applicaion.properties
       -webapp
            -WEB-INF
                 -jsp
                     -homeView.jsp

在 application.properties 我得到了:

  spring.view.prefix: /WEB-INF/jsp/
  spring.view.suffix: .jsp 

其余端点/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]

我应该将视图放在哪里以便应用可以找到它们?

【问题讨论】:

标签: java spring spring-mvc spring-boot


【解决方案1】:

感谢geoand的回答我添加了

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

到 pom 并且它起作用了。

【讨论】:

    猜你喜欢
    • 2016-01-29
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2019-10-28
    • 2020-07-02
    • 2017-03-23
    • 2014-12-29
    • 2014-04-07
    相关资源
    最近更新 更多