讀取自定義字段
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