spring boot集成maven profile

1.pom文件bulid配置

<build>
    <filters>
        <filter>src/main/filters/${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <!-- springboot把${}改成了@@,使用一下配置可以恢复成${}接收变量
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <encoding>utf-8</encoding>
                <useDefaultDelimiters>true</useDefaultDelimiters>
            </configuration>
        </plugin>
        -->
    </plugins>
</build>

2.pom文件中profiles配置

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>development</env>
        </properties>
        <!--默认使用开发环境-->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>
    <profile>
        <id>pre</id>
        <properties>
            <env>preProduct</env>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>product</env>
        </properties>
    </profile>
</profiles>

3.src/main/filters/目录下开发环境配置距离,文件名development.properties

#开发环境配置
###### 数据源配置
maven.datasource.ip=192.12.0.90
maven.datasource.port=1234
maven.datasource.database=test
maven.datasource.username=dev
maven.datasource.password=7576

######日志配置
maven.logback.logpath=/data/logs/car
maven.logback.root.level=INFO
maven.logback.rolling.trace.level=INFO
maven.logback.rolling.file.level=INFO
maven.logback.console.level=INFO

4.resources目录下properties和xml文件接收变量

spring.datasource.username=@maven.datasource.username@
spring.datasource.password=@maven.datasource.password@

<filter class="ch.qos.logback.classic.filter.LevelFilter">
   <level>@maven.logback.rolling.file.level@</level>
   <onMatch>ACCEPT</onMatch>
   <onMismatch>DENY</onMismatch>
</filter>
<property name="LOG_PATH" value='@maven.logback.logpath@' />
5.按环境配置打包命令举例:

mvn clean -DskipTests=true package -P prod






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值