![](/img/trans.png)
[英]Spring Boot - inject from application.yml and application.properties
[英]how to inject maven profile's properties in application.properties with spring boot
我在pom.xml中定義了三個配置文件
<profiles>
<profile>
<id>development</id>
<properties>
<activatedProperties>development</activatedProperties>
<env.identifier>dev</env.identifier>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qualification</id>
<properties>
<activatedProperties>qualification</activatedProperties>
<env.identifier>klif</env.identifier>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<activatedProperties>production</activatedProperties>
<env.identifier>prod</env.identifier>
</properties>
</profile>
</profiles>
我也將構建節點修改為:
<build>
<finalName>myApplication</finalName>
<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>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
我創建了三個屬性文件,並以此模式命名:application- [profileId] .properties。 在一般的application.properties中,我定義了property:
spring.profiles.active=@activatedProperties@指定彈簧啟動要使用的配置文件。 我還為日志文件定義了一個文件,如下所示:
logging.file = logs / facade_ @ env.identifier @ .log問題是,即使指定了配置文件,我啟動應用程序時,也總是得到env.identifier開發人員的值。 如何解決這個問題? 謝謝
更新
您可能缺少Maven資源插件:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
...
</plugins>
然后在您的命令中只需添加:
mvn resources:resources
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.