Java Spring 4属性资源占位符配置器不';t跨模块解析${..}占位符

Java Spring 4属性资源占位符配置器不';t跨模块解析${..}占位符,java,spring,properties,configuration,placeholder,Java,Spring,Properties,Configuration,Placeholder,我的应用程序中有两个模块: 核心 网 core模块在spring/applicationContext core.xml上下文中包含以下属性占位符配置: <bean id="coreProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list>

我的应用程序中有两个模块:

  • 核心
core
模块在
spring/applicationContext core.xml
上下文中包含以下属性占位符配置:

<bean id="coreProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>classpath:/properties/*.properties</value>
            <value>classpath:/profiles/${build.profile.id}/properties/*.properties</value>
            <value>file:${ui.home}/profiles/${build.profile.id}/properties/*.properties</value>
        </list>
    </property>
</bean>

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreResourceNotFound" value="false"/>

    <property name="properties" ref="coreProperties" />
</bean>

<bean id="propertySourcesPlaceholderConfigurer" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
如果我将此值注入
核心
@组件

@Value("${resource.suffix}")
private String resourceSuffix;
该属性已正确解析

但是,如果我在
web
模块内的bean中添加相同的配置,这也会简单地加载核心配置:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/servlet-context.xml /WEB-INF/application-security.xml
        classpath*:/spring/applicationContext-core.xml</param-value>
</context-param>

上下文配置位置
/WEB-INF/servlet-context.xml/WEB-INF/application-security.xml
classpath*:/spring/applicationContext-core.xml
然后不解析属性,将
resourceSuffix
值设置为以下字符串文字值
${resource.suffix


我遗漏了什么?

我相信这与spring如何与前置/后置处理器协同工作有关

基本上,您可以使用重复的定义或使用不同的机制来加载属性

据我所知,在Spring3.1之前,复制是唯一的方法


更多关于@Value(${resource.suffix})的信息还是在属性上,而不是在constructure参数上,对吗?您还确定web模块bean是由spring实例化/扫描的吗?它位于
@Controller
中的一个字段上,并且该bean被扫描,因为它还注入了其他
@Autowired
bean。哪些上下文正在实例化“web”模块?你能试着将propertySourcesPlaceholderConfigurer移动到该上下文中吗?我会尝试复制
propertySourcesPlaceholderConfigurer
,因为我还需要解析
核心
模块上的一些属性。谢谢你,Mite。现在我必须阅读所有Eugen文章,从一些与Spring配置相关的文件中节省我的空间挫折感。我认为@PropertySource是一个更好的选择,除非是遗留代码,否则复制是一条出路
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/servlet-context.xml /WEB-INF/application-security.xml
        classpath*:/spring/applicationContext-core.xml</param-value>
</context-param>