Spring Boot Did not find handler method for [/WEB-INF/views/index.html]

Spring Boot Did not find handler method for [/WEB-INF/views/index.html]

使用spring boot进行开发的时候,把静态的html页面放到了web-inf之下,然后添加了如下的配置

spring.mvc.view.prefix=/WEB-INF/views/
spring.view.suffix=.html

程序启动访问index.html页面,一直都是404,控制台打印Did not find handler method for [/WEB-INF/views/index.html]

就是说没有配置这个链接,但是这个文件确实是存在的,一时有点懵。

百度说这个错误的原因是因为没有对应的解析html的解析器,可以参考http://stackoverflow.com/questions/13616821/make-html-default-view-spring-mvc

只要添加了对应的解析器就可以了,我使用了thymeleaf模板去解析html。

需要在pom.xml中添加对应的jar包

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

之后在application.properties中添加

#配置解析html
spring.thymeleaf.prefix=/WEB-INF/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时设置为false,否则看不到实时的页面
spring.thymeleaf.cache=false

这样再次访问就ok了,但是thymeleaf对html页面格式比较严格,每个标签都必须有对应的结束标签,否则就会报错

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值