spring boot项目运行问题

时间:2017-12-18 09:38:35

标签: java spring-boot

我使用" spring tool suite"创建了spring boot starter项目。当我运行项目时,index.jsp页面没有加载。但index.html可以很好地加载。

我的文件夹结构如下

enter image description here

我的家庭控制器

package com.programmingfree.springservice;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String home() {
        return "index";
    }

}

我如何运行index.jsp

2 个答案:

答案 0 :(得分:0)

您正在使用弹出启动的默认配置,请查看ThymeleafProperties.java.html是后缀的默认设置:

@ConfigurationProperties(
    prefix = "spring.thymeleaf"
)
public class ThymeleafProperties {
    private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
    private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
    public static final String DEFAULT_PREFIX = "classpath:/templates/";
    public static final String DEFAULT_SUFFIX = ".html";
    private boolean checkTemplate = true;
    private boolean checkTemplateLocation = true;
    private String prefix = "classpath:/templates/";
    private String suffix = ".html";
    private String mode = "HTML5";
    //......
}

所以你必须在application.properties中自定义你的配置:

spring.thymeleaf.prefix=classpath:/templates/  
spring.thymeleaf.suffix=.jsp

答案 1 :(得分:0)

你在application.properties中有下一行吗?

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

资源链接在运行时在模板中重写,这要归功于为Thymeleaf和FreeMarker自动配置的ResourceUrlEncodingFilter。您应该在使用JSP时手动声明此过滤器。 spring doc