1.打包成jar包
引入maven插件
<build> <finalName>springboot</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin> </plugins> </build>
打包: mvn package
2.打包成war包
pom中的packaging改成war方式
tomcat引用改成:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
Main方法修改:
继承SpringBootServletInitializer类,重构configure方法.
@SpringBootApplication public class App extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(App.class); } public static void main(String[] args){ SpringApplication.run(App.class, args); } }
3.多环境部署
创建application-dev.properties, application-test.properties, application-product.properties 配置文件
application.properties 中设置启用配置文件: spring.profile.active=dev