问题描述:外部tomcat无法加载springBoot启动类
我的验证过程:
1.第一步检查pom配置,确保不采用springBoot内置的tomcat
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
//排掉内置的tomcat
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
//增加tomcat provide依赖,供编译时使用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2. idea构建标准的web [war包] 目录结构
3.发现tomcat内部还是跑不起来,没有加载springBoot启动类
4.检查使用写了 SpringBootServletInitializer的子类实现
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(HelloWorldMainApplication.class);
}
}
5.再跑发现还是跑步起来
6.检查idea下对应的artifact下是对应的lib包下是否有对应的jar包,有
7.再跑tomcat,发现还是跑不起来,springBoot启动类无法加载
8.将项目达成war包,同时检查war包下是否有对应的jar包,皆有,图如下
9.部署在tomcat下webapps里面,发现依然没有加载springBoot启动类
10.开始怀疑tomcat的版本,问题,自己用的是tomcat6,改成tomcat7,OK,一切完美
11.总结,还是要理智分析问题,才行