Can I inject properties from Maven (passwords defined in settings.xml) into my Spring container?

后端 未结 4 1285
自闭症患者
自闭症患者 2020-12-25 15:08

I define passwords to servers via properties I define in my ~/.m2/settings.xml (could be anywhere, though, including pom.xml) for my deployment plugin. I\'d like to use the

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 15:41

    You can define your values in property file and refer them using ${my-pw-key} in pom.xml and create a properties file by using plugin properties-maven-plugin

            
                org.codehaus.mojo
                properties-maven-plugin
                1.0.0
                
                    
                        initialize
                        
                            read-project-properties
                        
                        
                            
                                ${basedir}/src/main/resources/env.properties
                            
                        
                    
                
            
    

    Properties file (env.properties)

    my-pw-key=abc&123 #your password here
    

    And then run maven mvn initialize package (initialize to load values from property file)

提交回复
热议问题