How to set spring active profiles with maven profiles

后端 未结 6 892
耶瑟儿~
耶瑟儿~ 2020-12-01 01:05

I have an application with maven as a build tool.

I am using maven profiles to set up different properties from different profiles.

What i would like to do i

6条回答
  •  佛祖请我去吃肉
    2020-12-01 01:59

    For a Spring Boot application, one can add a property in the Maven profile in pom.xml and then reference that property in application.properties.

    Add Maven profiles to pom.xml with, for example, a property called spring.profile.from.maven:

    
        
            postgres
            
                true
            
            
                postgres
            
            
                
                    org.springframework.boot
                    spring-boot-starter-data-jpa
                
                
                    org.postgresql
                    postgresql
                    runtime
                
            
        
        
            noDb
            
                noDb
            
        
    
    

    Reference the Maven property in application.properties:

    spring.profiles.include=@spring.profile.from.maven@
    

    With this setup, running maven with the postgres Maven profile or with no profile adds the postgres Spring profile to the list of Spring's active profiles, while running maven with the noDb Maven profile adds the noDb Spring profile to the list of Spring's active profiles.

提交回复
热议问题