一、静态资源配置
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>