读取自定义字段
1.定义字段
application.properties
path.pictrue.brand=/home/abc/Pictures/brand/
application-prod.properties
path.pictrue.brand=/home/xyz/Pictures/brand/
2.读取字段
PropertiesConfig.java
@Component public class PropertiesConfig { @Value("${path.pictrue.brand}") public String pathBrand; }
3.在需要使用的类中:
@Autowired private PropertiesConfig pConfig; public void testPicture() { System.out.println(pConfig.pathBrand); }
4.生产jar包后:
java -jar xxxxx.jar 使用的是application.properties
java -jar -Dspring.profiles.active=prod xxxxx.jar 则使用的是application-prod.properties
springboot配置文件自定义字段在dev/prod下的自动读取
原文:https://www.cnblogs.com/anenyang/p/12919179.html