how to use Spring Boot profiles

前端 未结 12 1171
忘了有多久
忘了有多久 2020-12-04 21:14

i have application.yml,application-dev.ymlandapplication-dev.yml

  1. I\'m using the maven command mvn spring-boot:run
12条回答
  •  自闭症患者
    2020-12-04 21:58

    If you are using maven, define your profiles as shown below within your pom.xml

    
    
        local
        
            true
        
        
            dbUrl
            dbuser
            dbPassword
            dbDriver
        
    
    
        dev
        
            dbUrl
            dbuser
            dbPassword
            dbDriver
        
        
            
                org.postgresql
                postgresql
            
        
    
    
        prod
        
            dbUrl
            dbuser
            dbPassword
            dbDriver
        
    
    

    By default, i.e if No profile is selected, the local profile will always be use.

    To select a specific profile in Spring Boot 2.x.x, use the below command.

    mvn spring-boot:run -Dspring-boot.run.profiles=dev
    

    If you want want to build/compile using properties of a specific profile, use the below command.

    mvn clean install -Pdev -DprofileIdEnabled=true
    

提交回复
热议问题