springboot配置文件自定义字段在dev/prod下的自动读取


读取自定义字段

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM