关于war包转换成jar包的执行
遇到的问题
- Tomcat版本与war包、JDK不兼容,可能会出现war解压,但启动类不执行的效果。
解决步骤
- 在启动类增加初始化配置
public class TimesDataExchangeApp extends SpringBootServletInitializer {
/* 解决druid 日志报错:discard long time none received connection:xxx */
static {
System.setProperty("druid.mysql.usePingMethod","false");
}
@Override
protected 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>
原文地址:https://blog.csdn.net/TheLongir/article/details/145307567
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!