一、靜態資源配置
a、配置application.yml
spring: resources: static-locations: classpath:/static/
二、打包war發布
a、需要打成war包
<packaging>war</packaging>
<!-- maven項目packaging為war類型時,必須要加這個插件 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>

b、配置pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
c、啟動類
@SpringBootApplication(scanBasePackages = { "com.wuxi" })
public class MySpringApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception {
SpringApplication.run(MySpringApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(MySpringApplication.class);
}
}
d、執行maven命令
clean package:在target目錄下生成war包
三、打jar包發布
a、配置pom.xml(運行mvn package命令即可打包)
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
b、運行命令
java -jar 【打的jar包名】
四、微服務打包構建
父模塊
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!--springboot 打包插件 ,不然報錯 Unable to find main class
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
-->
</plugins>
<resources>
<!--
src/main/java目錄下的mapper.xml文件,需此配置才能打進包里
-->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
子模塊(沒有啟動器的模塊不能加)
<!-- 打包插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
