Springboot或Springcloud服务多环境配置

1. boot项目多环境配置
application.properties中,spring.profiles.active=@filter-resource-name@
Springboot或Springcloud服务多环境配置_第1张图片
pom中配置

   xxx
   
      src/main/resources/application-${filter-resource-name}.properties
   
   
      
         src/main/resources
         true
         
            filters/*
            filters/*
            application-dev.properties
            application-test.properties
            application-prod.properties
         
      
      
         src/main/resources
         true
         
            application-${filter-resource-name}.properties
         
      
   


2. 以文件方式
在src/main/java同级目录下添加env文件夹
下面再添加环境文件夹
Springboot或Springcloud服务多环境配置_第2张图片
这种方式读取配置中的信息时,使用@@ 如 username=@xxxx@ xxxx是env下面的properties中存在的key

pom中配置

    dev

    
        dev
        
            dev
        
        
            true
        
    
    
        test
        
            test
        
    
    
        prerelease
        
            prerelease
        
    
    
        production
        
            production
        
    

   
      src/main/env/${environment}/config-server.properties
      src/main/env/${environment}/eureka.properties
      src/main/env/${environment}/ms.properties
      src/main/env/${environment}/rabbitmq.properties
   
   
      
         src/main/resources
         true
      
   
   
      
         src/test/resources
         true
      
   

   
      
      
         org.springframework.boot
         spring-boot-maven-plugin
      
   


你可能感兴趣的:(cloud)