更改pom.xml:
1、<packaging>jar</packaging> 改为 <packaging>war</packaging>
2、<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
改为
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 排除内置容器 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
或
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3、新增servlet-apijar包
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
修改启动类
@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
@EnableHystrix
@MapperScan("com.yw.xxx.dao")
public class XApplication{
public static void main(String[] args) {
SpringApplication.run(XApplication.class, args);
}
}
改为
@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
@EnableHystrix
@MapperScan("com.yw.xxx.dao")
public class XApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(XApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(XApplication.class);
}
}
maven 打包
mvn clean package -Dmaven.test.skip=true
部署:
本地Tomcat加启动配置参数
tomcat8.exe方式启动->tomcat8w.exe 当前文件调出dos窗口执行service install tomcat8 安装服务,服务名称是tomcat8
运行tomcat8w.exe ->Java-> Java options中追加参数。
startup.bat方式启动->catalina.bat ->加一行set "JAVA_OPTS=参数"
Linux启动->catalina.sh ->加一行JAVA_OPTS="$JAVA_OPTS 参数"