springBoot普通加载信息:
springBoot默认加载的是 src/main/resources文件下的application.properties文件;
可以在application.properties中配置对应的配置信息可以在文件中通过${key}获取对应的信息;
但是如何把对应的 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 同时支持多个环境配置如下:
目录结构如下:
加载方式更改:
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环境