maven profile动态选择配置文件

resources/config/appclication-dev.properties   配置如下:
profile.env=dev
env.datasource.driver=com.mysql.cj.jdbc.Driver
env.datasource.jdbcUrl=jdbc:mysql://192.168.42.29:3306/dev?useUnicode=true&characterEncoding=utf-8&useSSL=false
env.datasource.username=ctl
env.datasource.password=liebe

resources/config/appclication-proc.properties   配置如下:
profile.env=proc
env.datasource.driver=com.mysql.cj.jdbc.Driver
env.datasource.jdbcUrl=jdbc:mysql://192.168.42.29:3306/proc?useUnicode=true&characterEncoding=utf-8&useSSL=false
env.datasource.username=ctl
env.datasource.password=liebe

resources/config/appclication-test.properties   配置如下:
profile.env=test
env.datasource.driver=com.mysql.cj.jdbc.Driver
env.datasource.jdbcUrl=jdbc:mysql://192.168.42.29:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
env.datasource.username=ctl
env.datasource.password=liebe

resources/config.properties   配置如下:
env=${profile.env}
jdbc.driver=${env.datasource.driver}
jdbc.url=${env.datasource.jdbcUrl}
jdbc.username=${env.datasource.username}
jdbc.password=${env.datasource.password}

执行mvn compile -P proc 后target编译后的额config.properties变更为:
env=proc
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.42.29:3306/proc?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=ctl
jdbc.password=liebe

执行mvn compile -P test 后target编译后的额config.properties变更为:
env=test
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.42.29:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=ctl
jdbc.password=liebe

执行mvn compile -P dev 后target编译后的额config.properties变更为:
env=dev
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.42.29:3306/dev?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=ctl
jdbc.password=liebe


    
      
      dev 
       
        dev  
      
      
      
        true
      
    
    
      
      proc 
       
        proc  
      
    
    
      
      test 
       
        test   
      
    
  
  
    
      src/main/resources/config/application-${profiles.active}.properties
    
    pmanager
    
      
        src/main/java
        
          **/mapper/*Mapper.xml
          **/mappers/*Mapper.xml
        
      
      
        ${basedir}/src/main/resources
        true
      
    
  

你可能感兴趣的:(maven profile动态选择配置文件)