SpringBoot工程运行有三种方式:
复制代码<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 当执行maven的哪个构建周期时,使用springboot打包插件 -->
<executions>
<execution>
<goals>
<!-- 表示当运行mavn package打包时,使用Springboot插件打包 -->
<goal>repackage</goal>
</goals>
</execution>
</executions>
<!-- 指定应用启动类 -->
<configuration>
<mainClass>com.taotao.portal.PortalApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
复制代码mavn clean package -Dmaven.test.skip=true
复制代码java -jar xxx.jar
复制代码
// 继承SpringBootServletInitializer,重写配置方法。让SpringBoot启动类和Tomcat原生生命周期建立联系。这样我们启动Tomcat时,Tomcat才能正常启动SpringBoot应用
public class ManagerApplication extends SpringBootServletInitializer{
// 将SpringBoot启动类和Tomcat建立联系
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ManagerApplication.class);
}
public static void main(String[] args) throws InterruptedException {
SpringApplication application = new SpringApplication(ManagerApplication.class);
//application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
}
复制代码<dependencies>
// ...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
// ...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 当执行maven的哪个构建周期时,使用springboot打包插件 -->
<executions>
<execution>
<goals>
<!-- 表示当运行mavn package打包时,使用Springboot插件打包 -->
<goal>repackage</goal>
</goals>
</execution>
</executions>
<!-- 指定应用启动类 -->
<configuration>
<mainClass>com.taotao.portal.PortalApplication</mainClass>
</configuration>
</plugin>
<!-- 配置maven打war包插件 -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
复制代码mvn clean package -Dmaven.test.skip=true
将打好的war包,拷贝到%TOMCAT_HOME%/webapps/, 然后正常启动tomcat即可
复制代码<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 当执行maven的哪个构建周期时,使用springboot打包插件 -->
<executions>
<execution>
<goals>
<!-- 表示当运行mavn package打包时,使用Springboot插件打包 -->
<goal>repackage</goal>
</goals>
</execution>
</executions>
<!-- 指定应用启动类 -->
<configuration>
<mainClass>com.taotao.portal.PortalApplication</mainClass>
</configuration>
</plugin>
<!-- 配置maven打war包插件 -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</build>
复制代码mavn clean package -Dmaven.test.skip=true
复制代码java -jar xxx.war