springboot多环境

针对于生产、开发、测试,预生产,会有多个数据配置版本,所以需要考虑版本控制的问题。

进行如下配置:

pom.xml配置

第一步:插件配置

        ${project.artifactId}
        
            
                src/main/resources
                true
                
                    **/*
                
            
        
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            

            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    true
                
            

            
                maven-resources-plugin
                2.6
                
                    UTF-8
                    
                        ${*}
                    
                    true
                
            
        
    
profiles在xml中的配置

其中activeByDefault为true表示默认激活的配置。


        
            test
            
                true
            
            
                
                    profiles/test.properties
                
            
        
        
            production
            
                false
            
            
                
                    profiles/production.properties
                
            
        
    

文件夹配置

在主项目下建立profiles文件夹,里面放置*.properties,对应上面的profiles配置。


image.png

使用与打包

使用maven命令进行编译或者打包:mvn clean install -Dskip.test=true -Ptest
打完的包在target目录下,命令执行完后下面也会有路径提示的。
在IDEA的右侧,也可以进行选择:

image.png

你可能感兴趣的:(springboot多环境)