springboot(七) 常见错误

1.1.1. 启动错误1

 

关键错误(丢失了web容器的工厂,也就是说我们并没有把它作为一个web应用来启动):

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

 

解决:

 

 

让Spring Boot来自动选择并且完成web的相关加载工作。

1.1.2. Slf4j日志警告

 

 

 

提示我们当前的项目中slf4j引入了2个,导致了jar冲突。

 

解决:

1、 删除自己引入到slf4j的依赖

 

 



再次启动,发现警告没了:

 

1.1.3. 解决jsp访问404的问题

由于Spring boot使用的内嵌的tomcat,而内嵌的tamcat是不支持jsp页面的,所有需要导入额外的包才能解决。

 

 

<dependency>

<groupId>org.apache.tomcat.embed</groupId>

<artifactId>tomcat-embed-jasper</artifactId>

<scope>provided</scope>

</dependency>

 

重新启动进行测试:

 

1.1.4. 拦截器中的UserService空指针异常

分析:由于添加拦截器时,直接对UserLoginHandlerInterceptor进行new操作,导致UserService无法注入,所以有空指针异常。

 

解决:

 

 

 

 

 

1.1.5. 路径问题

现在我们进入Servlet的路径为”/”,访问*.html页面没问题,但是,访问 /service/* 就会有问题,所以需要改一下js,将原有的/service/ 改为 /

 

 

posted @ 2018-09-12 11:15  ForgotTheMemory  阅读(407)  评论(0)    收藏  举报