Springboot + Maven 项目配置文件管理

项目目录

project_dir.png

示例项目地址 Github链接

Maven多环境配置



    
        dev
        
            true
        
        
            dev
        
    
    
        test
        
            test
        
    
    
        prod
        
            prod
        
    

Maven Filters 配置

基础属性配置, 配置后响应的文件中的字段会转化为 Maven Properties




    src/main/resources/conf/${profiles.active}/test.properties
    src/main/resources/conf/${profiles.active}/test2.properties

根据项目实际情况配置

Maven Resources 配置

** 开启 filtering 默认为 false



    
        src/main/resources
        
        true
    

application.yaml(.properties) 配置

server:
  port: 9001
  servlet:
    context-path: /with-maven

spring:
  profiles:
    active: @profiles.active@

# admin properties
sys:
  admin:
    id: ${admin.id} # 可以使用${}但是需要注意引入的字段名不能跟yaml(properties)中冲突
    name: @admin.name@ # 标准的引用maven properties属性引用
    age: @admin.age@
    address: @admin.address@

你可能感兴趣的:(Springboot + Maven 项目配置文件管理)