首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@ActiveProfile和spring.profiles.active

@ActiveProfile和spring.profiles.active
EN

Stack Overflow用户
提问于 2013-03-05 16:01:39
回答 2查看 11.1K关注 0票数 4

这是我的applicationContext定义的一部分,用于检索一些属性。

代码语言:javascript
复制
 <!-- get some properties -->
<context:property-placeholder
        ignore-resource-not-found="false" ignore-unresolvable="false"
        location="classpath:/properties/${spring.profiles.active:test}/some.properties"/>

如您所见,我让spring.profiles.active决定将读取哪些属性。我的测试注释如下:

代码语言:javascript
复制
@ActiveProfile("integration")

您猜对了,我的spring配置文件实际上与部署/测试应用程序的环境匹配。我的location属性仍然被解析为“/properties/test/ome.properties”。当然,这是因为在这种情况下,spring.profiles.active似乎没有得到解决。

我如何才能获得正确的属性?

EN

回答 2

Stack Overflow用户

发布于 2013-03-05 17:05:25

这是因为active profiles 可以通过系统属性激活(但如果是@ActiveProfiles,则以另一种方式工作)。

就像这样:

代码语言:javascript
复制
<beans profile="dev,prod,qa">
    <context:property-placeholder location="classpath:some.properties" ignore-unresolvable="true"/>
</beans>

<beans profile="test">
    <context:property-placeholder location="classpath:some-test.properties" ignore-unresolvable="true"/>
</beans>

此外,您还可以尝试将location="classpath:/properties/${spring.profiles.active:test}/some.properties"更改为location="classpath:/properties/${spring.profiles.active}/some.properties"

票数 1
EN

Stack Overflow用户

发布于 2013-03-06 11:12:37

见票证:https://jira.springsource.org/browse/SPR-8982#comment-88498

有人已经提出了这样的要求:

通过"-Dspring.profiles.active“或其他systemProperty从命令行重写运行时测试指定的@ActiveProfile的选项

我的意见是:

或者它应该设置属性spring.profiles.active。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15228441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档