springboot打包时,去掉资源文件,可按照如下配置
<build> <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>*.properties</exclude> <exclude>*.log4j2.xml</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build>
但这样配置后,在eclipse中启动springboot项目,则会出现读取不到配置资源的情况,所以在eclipse启动项目时,需要注释掉如下配置
<resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude>*.properties</exclude> <exclude>*.log4j2.xml</exclude> </excludes> </resource> </resources>
项目打成jar包后,运行时,可将配置文件放入jar包同级目录下或者在同级的config目录下(放入classpath下或者classpath下config目录下也可以,但是打成jar包,就需要一起打包出来)
配置文件加载顺序为:
jar包同级目录下的config文件夹下配置
jar包同级目录下配置
classpath下config目录下配置
classpath下配置
java -Xms100m -Xmx100m -jar myboot001-0.0.1-SNAPSHOT.jar &
也可指定加载配置文件的地址
java -Xms100m -Xmx100m -jar myboot001-0.0.1-SNAPSHOT.jar --spring.config.location=configs/application.properties
以DEBUG方式启动
java -Xms100m -Xmx100m -jar myboot001-0.0.1-SNAPSHOT.jar --spring.config.location=configs/application.properties --debug
原文地址:https://www.cnblogs.com/qq931399960/p/9962401.html
时间: 2024-10-03 09:45:24