您的位置:首页 > 编程语言 > Java开发

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

2017-03-29 19:04 639 查看

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页面格式比较严格,每个标签都必须有对应的结束标签,否则就会报错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring html java springboot
相关文章推荐