我的resources目录结构为: resources/config/filter-dev.properties resources/application.yml
filter-dev.properties 配置为:serverPort=8088
父pom中定义了env标签以确定使用的是哪一个环境的配置
<properties>
<skipTests>true</skipTests>
<env>dev</env>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
子pom中定义:
<build>
<finalName>practice-web-release</finalName>
<filters>
<filter>src/main/resources/config/filter-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在application.yml中使用${serverPort}取不到值,我应该如何配置这种取值方式呢? 我是一个spingboot新手,看到网上有很多的多环境配置方式,但是大部分都是配置了多个一样配置项的配置文件,只是更改了部分参数,于是我想到能不能使用一个application.yml配置文件动态的获取对应环境的参数
Comment From: wilkinsona
Courtesy of Google translate:
Using ${serverPort} in application.yml cannot get a value, how should I configure this value method? I am a newbie to spingboot, and I saw that there are many multi-environment configuration methods on the Internet, but most of them are configuration files configured with multiple configuration items, only some parameters have been changed, so I thought about whether I can use an application.yml configuration The file dynamically obtains the parameters of the corresponding environment
A file named filter-dev.properties
won't be loaded by default. You would need to have the dev
profile enabled and also configure Spring Boot to look for files named filter
rather than just the default of application
. There's some more information about this in the documentation.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.