快好知 kuaihz

springboot项目搭建过程中遇到的错误点及解...

初学SpringBoot,此过程中遇到各种问题,这里做记录,以防后面忘记了

1.要运行的application类启动时报:

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.

    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]

    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]

解决方案:

未给要运行的application class添加注解 @EnableAutoConfiguration,再次启动没有该错误

2.访问 http://localhost:8080/hello 页面报错:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Jun 28 10:42:48 CST 2018

There was an unexpected error (type=Internal Server Error, status=500).

Error resolving template "hello springboot", template might not exist or might not be accessible by any of the configured Template Resolvers

错误原因:由于application类使用了注解@Controller,而使用@Controller注解时需要有对应的页面存在,如jsp/html等,所以解决方式有如下两种:

a.将注解@Controller换成 @RestController,再次访问没有该错误

b.在templates下添加一页面,如下图

application类中注解使用@Controller,sayHello方法返回该页面"index"

本站资源来自互联网,仅供学习,如有侵权,请通知删除,敬请谅解!
搜索建议:误点  误点词条  搭建  搭建词条  springboot  springboot词条  遇到  遇到词条  过程  过程词条  
综合

 再见了机顶盒! 中国又一新发明,...

高清品质同步,画质逼真无延迟,让您体验大屏带来的酣畅淋漓。如今很多人都喜欢装网络电视,其实没有必要,家里面放上这款同屏线,便能收看任何你想要看的节目。高清品质同...(展开)