Spring boot 项目打成war包并在idea中运行
1、 修改pom文件原来是jar改成<packaging>war</packaging>
2、 在pom文件中添加移除内置tomcat并且添加添加servlet-api的依赖。
<!--war包部署需要--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--<!– 移除嵌入式tomcat插件 –>--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
3、 启动类修改
public class BootApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
// SpringApplication.run(BootApplication.class, args);
// System.out.println("访问地址:localhost");
SpringApplication application = new SpringApplication(BootApplication.class);
application.run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(BootApplication.class);
}
}
4、 配置idea的tomcat启动
配置自己本地tomcat
然后在Deployment中找到自己的war
运行maven install,如果是部署那么双击package就可以啦。
运行就ok啦.