1.java -jar -Dlog4j.path=/app/bin/config/log4j.properties -Denv=dev /cpic/cpicapp/app/*.jar --spring.profiles.active-tb-test -server -Xms800m -Xmx800m -XX:PermSize=512m -XX:MaxPermSize=512m
-D需放在 *.jar之前 他能被代码System.getProperties()获取到
-- 需放在 *.jar之后,spring相关参数@Value
args 放在*.jar之后
2.pom文件build下resources
filter为true代表 自动替换占位符
<resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>i18n/**</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>i18n/**</include> </includes> </resource>
3.maven本地引包时,需在build resources下添加对应源和目标路径
添加dependency
<dependency>
<groupId>com.chinawayltd.java.spec</groupId>
<artifactId>globally-unique-id-generator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/globally-unique-id-generator-1.0.0-SNAPSHOT.jar</systemPath>
</dependency>
build->resources下添加(lib文件夹不在resources文件夹下时,要加)
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
spring-boot-maven-plugin下添加configruation
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
或者maven-compiler-plugin下添加<extdirs>src/main/resources/lib</extdirs>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <compilerArguments> <extdirs>${project.basedir}/src/main/resources/lib</extdirs> </compilerArguments> </configuration> </plugin>
4.--spring.profiles.active-tb-test和-Dspring.config.location
4.1.springboot 1.5.X版本
指定location后,还会去读取jar里的文件配置内容,优先级如下
加载配置文件时会在spring.config.location指定目录,结合默认路径 file:./config/,file:./,classpath:/config/,classpath:/,加载配置文件,优先级由高到低,文件名默认为application,扩展名properties,xml,yml,yaml
配置的生效顺序为:
- spring.profiles.active配置文件
- 系统参数spring.config.location
- file:./config/
- file:./
- classpath:/config/
- classpath:/
4.2.springboot 2.x版本
spring.config.location 设置后,只读取这个文件配置内容,不再读取其他地址的配置文件
根据官方文档表述,默认会读取
1. file:./config/
2. file:./config/*/
3. file:./
4. classpath:/config/
5. classpath:/
tips
Idea执行main方法无反应解决方案:点击Files-Settings-Plugins选项搜索Groovy选项,将后面方框中的对号删除,重启idea