2014-09-02 118 views
0

我有一个Spring引导应用程序,我不想注入属性。在我们以前的项目中,我们定义在我们context.xml一个PropertyPlaceholderConfigurer一次加载所有依赖模块的属性文件:Spring Java配置:PropertyPlaceholderConfigurer的“位置”等效

<bean id="propertyPlaceholderConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="ignoreResourceNotFound" value="true" /> 
     <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> 
     <property name="locations"> 
      <list> 
       <value>classpath:test.properties</value> 
       <value>classpath*:/META-INF/*.properties</value> 
      </list> 
     </property> 
    </bean> 

现在我正在寻找在Java的配置风格值得选择。我想我的标注配置类,如下所示:

@PropertySources(value = { @PropertySource("classpath:application.properties"), 
    @PropertySource("classpath*:/META-INF/*.properties") }) 

@PropertySource注释不喜欢通配符(这是有道理的,因为它是负责提取单个资源)。

任何想法,提示,解决方案?

+0

。请注意,声明'PropertyPlaceholderConfigurer'豆和'@ PropertySources'是不等价的。 – 2014-09-02 15:50:26

+1

[classpath-wildcard-in-propertysource]可能重复(http://stackoverflow.com/questions/14389995/classpath-wildcard-in-propertysource)。 – tmarwen 2014-09-02 15:53:54

+0

谢谢你们! – achingfingers 2014-09-02 15:55:23

回答

-1

雅,这是尴尬的PropertySource不支持通配符。上一个问题提出了一个合理的解决方案,我已经成功地使用了它。

classpath wildcard in @PropertySource

+2

您应该投票结束重复。 – 2014-09-02 15:49:48

+0

啊,谢谢Sotirios,我会在将来记住。 – dectarin 2014-09-02 15:56:49