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/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 Boot Did not find handler method for [/WEB-INF/views/index.html]
发布评论