1.Maven Profile Springboot 打包,动态切换

经测试,绝对管用。

要解决怎样的问题?

一键maven package ,可以指定 test,dev,prod 的版本,同时 该版本的变换 ,会 同样改变相应版本下的配置参数,适用于Springboot的方式。

1.POM文件 需要添加的


        #
    

    
        
        
            dev
            
                
                dev
            
            
                true
            
        
        
        
            test
            
                test
            
        
        
        
            prod
            
                prod
            
        
    

    
        
            
                src/main/resources
                true 
            
            
                src/main/resources/application-${spring.profiles.active}.yml
                false
            
        
        
            
                    org.springframework.boot
                    spring-boot-maven-plugin
                    ${springboot.version}
                    
                        
                            
                                repackage
                            

                        
                    
            
        

    

2.配置目录

1.Maven Profile Springboot 打包,动态切换_第1张图片

application.yml 配置

spring:
  profiles:
    active: #spring.profiles.active#


#该 yml 可以写一些公共的参数配置

#局部的参数 测试dev 的,启动容器获取参数测试

在IDEA 开发时 ,选择Pro1.Maven Profile Springboot 打包,动态切换_第2张图片版本,重启项目即相当于重新打包了,配置文件相应变化了; 

在IDEA 发布线上时,选择Pro版本,执行package 即可。

后续补充jekins 持续集成和自动化部署。

你可能感兴趣的:(Maven)