遇到的问题
- Tomcat版本与war包、JDK不兼容,可能会出现war解压,但启动类不执行的效果。
解决步骤
- 在启动类增加初始化配置
public class TimesDataExchangeApp extends SpringBootServletInitializer {/* 解决druid 日志报错:discard long time none received connection:xxx */static {System.setProperty("druid.mysql.usePingMethod","false");}@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {return builder.sources(TimesDataExchangeApp.class);}
- 修改pom文件
修改打包方式
<packaging>jar</packaging>
排除内置Tomcat
<!-- starter-web:spring-webmvc + autoconfigure + logback + yaml + tomcat --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!-- 排除内置的tomcat --><exclusions><exclusion><artifactId>org.springframework.boot</artifactId><groupId>spring-boot-starter-tomcat</groupId></exclusion></exclusions></dependency>
增加打包插件
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.2.3</version></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions><configuration><mainClass>com.xxl.job.admin.SnowyXxlJobApp</mainClass><includeSystemScope>true</includeSystemScope></configuration></plugin>
可能遇到的依赖
<!-- 添加 spring-boot-starter-tomcat 依赖,并设置 scope 为 provided --><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-loader</artifactId><version>${spring.boot-version}</version><scope>provided</scope></dependency>