SpringBoot2.0.X 打war包方式首先，我说下实际部署场景，现有服务器上都是tomcat7和jdk1.7，那么我们知道boot大部分用的都是jdk1.8和tomcat8，那么我们如何才能在不影响其他项目的情况下，部署我们的boot项目。
POM依赖
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.jeesite</groupId> <artifactId>jeesite-parent</artifactId> <version>4.1.0-SNAPSHOT</version> <relativePath>../parent/pom.xml</relativePath> </parent> <artifactId>jyzs</artifactId> <packaging>war</packaging> <name>JeeSite Boot</name> <url>http://jeesite.com</url> <inceptionYear>2013-Now</inceptionYear> <properties> <java.version>1.8</java.version> <fastjson.version>1.1.40</fastjson.version> <!-- 打war包属性配置 --> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <tomcat.version>8.5.35</tomcat.version> </properties> <dependencies> <!-- 核心模块 --> <dependency> <groupId>com.jeesite</groupId> <artifactId>jeesite-module-core</artifactId> <version>${project.parent.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 打成war包添加依赖--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- 打成war包添加依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency> <!-- fastjson json --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> <version>4.0</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.7.0</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.7</version> </dependency> <dependency> <groupId>net.sf.ezmorph</groupId> <artifactId>ezmorph</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <!-- Redis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.5.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!--WerbService CXF依赖--> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.2.4</version> </dependency> <!-- 二维码 --> <dependency> <groupId>net.glxn.qrgen</groupId> <artifactId>javase</artifactId> <version>2.0</version> </dependency> <!-- Word生成 --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.26-incubating</version> </dependency> <!-- Apache Base64 --> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.10</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>aliyun-repos</id> <name>Aliyun Repository</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>sonatype-repos</id> <name>Sonatype Repository</name> <url>https://oss.sonatype.org/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>sonatype-repos-s</id> <name>Sonatype Repository</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>aliyun-repos</id> <name>Aliyun Repository</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
等待jar包下载完毕后，然后大家根据自己的tomcat版本修改我上面贴上的代码配置就可以，还有jdk的版本。
然后在项目的根目录运行 mvn clean，然后mvn install打包。
Application启动类：
@SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { this.setRegisterErrorPageFilter(false); // 错误页面有容器来处理，而不是SpringBoot //Scoket线程 Thread mainThread = new Thread(new SocketServerThread()); mainThread.start(); return builder.sources(Application.class); } }
项目是打包了，我们还需要去配置tomcat，我们开始不是说了环境变量里面配置的是jdk1.7，下面开始单独指定tomcat的jdk版本：

打开tomcat的bin目录中setclasspath.bat，右键编辑，如下：

修改后保存，这样tomcat启动时就不会去找环境变量配置的JDK了，按照我们上面指定的路径去找jdk了。
到此就结束了。