之前一直好好的,突然就 读不到 @Value了。
查了好久,又找同事帮忙。 最后终于找到问题了。
解决办法:
<context:component-scan base-package="com.xxx/>
scan重复 导致类重复加载,第一次扫描的时候有值,第二次扫描加载的时候又没值了。
2. disconf 中的 propertyConfigurer
<bean id="platformConfigurer" class="com.baidu.disconf.client.addons.properties.ReloadablePropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:/rpc.properties</value>
<value>classpath:/environment.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="propertiesArray">
<list>
<ref bean="platformConfigurer"/>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="
com.baidu.disconf.client.addons.properties.ReloadingPropertyPlaceholderConfigurer" 改成
<bean id="propertyConfigurer" class="
org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer" ...