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

前端 未结 2 1691
清酒与你
清酒与你 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:26

    You can use Maven profiles to add a 'profile' property to the build:

    
        
            dev
            
                dev
            
        
    
    

    Then pass the value into your application using a system property, here's an example with surefire:

    
        maven-surefire-plugin
        
            
                ${profile}
            
        
    
    

    Finally this can be referenced in you application:

    
        
    
    

    Alternatively, if you are using Spring 3.1 or later you might find the XML profile feature meets your needs (although it may be overkill).

提交回复
热议问题