使用springboot遇到的的异常
2017-02-09 18:35
387 查看
Unregistering JMX-exposed beans on shutdown
把scope删掉就可以了。
MainApplication.java必须位于某个包下
对springboot的依赖必须放在最前面!否则Springboot的内嵌tomcat无法启动!
在进行
比如我配置了mybatis,但是没有设置datasource,这样这个应用就启动不了。而mybatis已经下载下来了,这时即便在pom中去掉mybatis,这时运行mvn package得到的war包中还是会包含mybatis,从而导致应用无法启动。
初始化问题
一般情况下,部署在服务器上要使用tomcat,本地调试直接用SpringBoot自带的tomcat
这就需要如下写法
ServletInitializer是Servlet初始化器,意思是当本应用作为tomcat的一个webapp时,就调用configure函数,这是tomcat容器调用的,这时整个应用就相当于Servlet。
当作为SpringApplication运行时,会执行main函数,但是不会执行上面的configure函数。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!--<scope>provided</scope>--> </dependency>
把scope删掉就可以了。
MainApplication.java必须位于某个包下
对springboot的依赖必须放在最前面!否则Springboot的内嵌tomcat无法启动!
Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-8.5.6.jar:8.5.6] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-8.5.6.jar:8.5.6] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.6.jar:8.5.6] ... 24 common frames omitted
在进行
mvn package之前,最好
mvn clean一下,这样就能够删除target目录下的多余jar包。如果不删除多余jar包,有可能会出错。
比如我配置了mybatis,但是没有设置datasource,这样这个应用就启动不了。而mybatis已经下载下来了,这时即便在pom中去掉mybatis,这时运行mvn package得到的war包中还是会包含mybatis,从而导致应用无法启动。
初始化问题
一般情况下,部署在服务器上要使用tomcat,本地调试直接用SpringBoot自带的tomcat
这就需要如下写法
public class MyApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(MyApplication.class); } public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
ServletInitializer是Servlet初始化器,意思是当本应用作为tomcat的一个webapp时,就调用configure函数,这是tomcat容器调用的,这时整个应用就相当于Servlet。
当作为SpringApplication运行时,会执行main函数,但是不会执行上面的configure函数。
相关文章推荐
- 使用springboot遇到的的异常
- 68. 使用thymeleaf报异常:Not Found, status=404【从零开始学Spring Boot】
- 【springboot】使用注解遇到的问题
- Springboot使用了ResponseBodyAdvice处理返回值异常?
- springboot使用thymeleaf 解析静态页面异常
- spring boot + dubbo开发遇到过的异常
- 使用 spring-boot 中各种异常整理
- 在idea里使用SpringBoot整合MyBatis时遇到的Mapper扫描不到的问题
- redis在spring和springboot中的使用方式以及遇到的坑
- spring boot开发遇到坑之spring-boot-starter-web配置文件使用教程
- SpringBoot+Freemarker 项目ftl中使用include的异常
- spring boot 项目增加flyway的使用遇到问题解决
- 89. Spring boot devtools使用异常【从零开始学Spring Boot】
- SpringBoot进阶之使用异常替代返回错误码(拦截异常并统一处理)
- 在maven项目中使用apache cxf中遇到异常 java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
- springboot的restController使用swagger遇到的问题。
- SpringBoot使用可能遇到的问题及解决方法
- 3 Springboot中使用redis,redis自动缓存异常处理
- Spring Boot中使用Feign调用时Hystrix提示异常:"could not be queued for execution and no fallback available."以及"Rejected command because thread-pool queueSize is at rejection threshold"
- SpringBoot 统一异常处理--- @ControllerAdvice 使用