gpt4 book ai didi

java - Spring 4 PropertySourcesPlaceholderConfigurer 不跨模块解析 ${..} 占位符

转载 作者:行者123 更新时间:2023-11-30 08:52:00 24 4
gpt4 key购买 nike

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

  • 核心
  • 网络

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>

考虑到我有以下属性:

resource.suffix=.min

如果我在 core @Component 中注入(inject)这个值:

@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>

然后该属性未解析,resourceSuffix 值设置为以下字符串文字值 ${resource.suffix

我错过了什么?

最佳答案

我认为这与 spring 如何与预处理器/后处理器一起工作有关。

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

据我所知,在 spring 3.1 之前,复制是唯一的方法。

更多关于 http://www.baeldung.com/2012/02/06/properties-with-spring/#parent-child

关于java - Spring 4 PropertySourcesPlaceholderConfigurer 不跨模块解析 ${..} 占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30347929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com