之前springboot要打war包,丢进tomcat里面运行,根据网上不少方法试过,但是一旦打war包,本地就必须也丢进tomcat
没法以Appcation方式直接启动
经过不懈努力重新找到一种方式
第一步:添加spring-boot-starter-tomcat的provided依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> |
第二步:添加maven-war-plugin插件
<build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> |
第三步:修改package 打包方式
<packaging>war</packaging> |
第四步:修改启动类
第二步:添加maven-war-plugin插件@SpringBootApplication public class MainApplication extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){ return builder.sources(MainApplication.class); } } |
mvn clean install -Dmaven.test.skip=true
打包后扔进tomcat里面,亲测启动访问时ok的
如果要以直接运行Application,需要将<scope>provided</scope>去掉,测试发现不去掉也可以直接启动
打jar包的插件
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> |