How can I use maven profile Id value in spring bean files?

前端 未结 2 1664
清酒与你
清酒与你 2021-01-23 19:03
mvn -P dev

If I build my project using profile dev, then I want to use dev.properties in my spring bean like below. Is it possible ? If so , how could

2条回答
  •  清歌不尽
    2021-01-23 19:38

    Create a properties file that will be populated using Maven's resource filtering that specifies the profile you are using at build time.

    build.properties

    activatedProfile=${profileId}
    

    pom.xml (You don't need to filter the complete directory, customise as required)

     
        
            
                src/main/resources
                true
            
        
        
    

    Add a profileId (or whatever you want to call it) property under each different profile:

     
         dev
         
            dev
         
     
     
         qa
         
            qa
         
     
    

    You can then use ${activatedProfile}.properties as value for a bean

    
        
    
    

提交回复
热议问题