springboot maven 多环境配置yml

  1. 配置maven环境
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <package.environment>dev</package.environment>
        </properties>
        <!-- 是否默认 true表示默认-->
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <profile>
        <id>test</id>
        <properties>
            <package.environment>test</package.environment>
        </properties>
    </profile>

    <profile>
        <!-- 生产环境 -->
        <id>qa</id>
        <properties>
            <package.environment>qa</package.environment>
        </properties>
    </profile>
</profiles>`
  1. 资源文件在这里插入图片描述

application.yml

spring:
  profiles:
    active: @package.environment@

application-dev.yml

spring:
  datasource:
    type: org.springframework.jdbc.datasource.DriverManagerDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.20.252/shlaunch?useUnicode=true&characterEncoding=utf-8&useSSL=true&autoReconnect=true
    username: shlaunch
    password: password

  jpa:
    database: mysql
    show-sql: true
    generate-ddl: true
    database-platform: org.hibernate.dialect.MySQL5Dialect
    hibernate:
      ddl-auto: update
server:
  port: 8081
logging:
  level:
    root: info
  pattern:
    console: '%d{yyyy-MMM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n'

    spring:

     mvc:
      static-path-pattern: /**


线上代码就不贴出来了 都是一样的

3.执行maven勾选中的yml

 <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.yml</include>
                    <include>application-${package.environment}.yml</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值