我在我的應用程序兩個模塊的佔位符:
- 核心
- 網絡
的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
這個值:
@Value("${resource.suffix}")
private String resourceSuffix;
該物業妥善解決。
但是,如果我在一個bean添加web
模塊,它只是加載核心配置以及內部相同的配置:
<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
。
我錯過了什麼?
的@Value( 「$ {} resource.suffix」)又是一個屬性,而不是在constuctur說法對不對? 你也確定Web模塊bean是由spring實例化/掃描的嗎? –
它位於'@ Controller'內的一個字段上,並且該bean被掃描,因爲它也有其他'@ Autowired' bean被注入。 –
哪個上下文實例化「web」模塊? 你可以嘗試將propertySourcesPlaceholderConfigurer移動到該上下文中嗎? –