springboot + maven 配置多环境properties和自定义application.properties

springBoot普通加载信息:

springBoot默认加载的是 src/main/resources文件下的application.properties文件

可以在application.properties中配置对应的配置信息可以在文件中通过${key}获取对应的信息;

202849_ibXP_1459447.png

202925_NVsO_1459447.png

但是如何把对应的 application.properties 更改名字那??

查询网上的资料很多都给出的建议是用注解@PropertySource(value="classpath:application1.properties")这种方式可以解决 获取 properties中对应参数值信息

这种方法普通的key-value信息是可以读取的;如上图中的name title desc ;

但是如果在application1.properties中定义 多环境配置:spring.profiles.active 属性是无效的(如下图);

spring.profiles.active=dev

如果src/main/resources下有多个配置文件(*.properties)多环境配置 properties 方法请参考:http://blog.didispace.com/springbootproperties/

把文件名不是application.properties 同时支持多个环境配置如下

目录结构如下:

204808_vm8k_1459447.png

加载方式更改:

204833_DFvw_1459447.png

pom.xml文件为:

<profiles>
   <profile>
      <id>dev</id>
      <properties>
         <env>dev</env>
      </properties>
      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>
   </profile>
   <profile>
      <id>test</id>
      <properties>
         <env>test</env>
      </properties>
   </profile>
</profiles>

 

<resources>
   <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      <includes>
         <include>*.properties</include>
      </includes>
   </resource>
   <resource>
      <directory>src/main/resources/${env}</directory>
      <filtering>true</filtering>
      <includes>
         <include>*.properties</include>
      </includes>
   </resource>
</resources>

默认为dev环境

 

 

转载于:https://my.oschina.net/u/1459447/blog/863392

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值