使用@Value注释的属性未在我的bean上设置.
我的上下文和类位于另一个项目的类路径中的jar内.它的spring上下文导入我的spring上下文,我的spring上下文从类路径加载一个配置文件,并包含各种bean定义.
懒惰加载没有在任何地方使用,我的jar使用Spring 3.1.4,使用我的jar的项目使用Spring 3.2.3.
当外部项目加载它的上下文(导入我的上下文)时,会加载显示属性文件的记录器
[main] INFO Loading properties file from class path resource [connector-config.properties] - (PropertyPlaceholderConfigurer.java:172:)
Run Code Online (Sandbox Code Playgroud)
摘自我的Spring背景:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
lazy-init="false">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:connector-config.properties</value>
</list>
</property>
</bean>
...
<!-- The actual beans referenced are not foo bar and com but should not be relevant to this issue -->
<bean id="requestGenerator" class="com.connector.RequestGenerator">
<constructor-arg name="foo" ref="foo" />
<constructor-arg name="bar" ref="bar" />
<constructor-arg name="com" ref="com" />
</bean>
Run Code Online (Sandbox Code Playgroud)
使用我的jar在项目的类路径上的配置文件
ruleType=PAUL
response.poolSize=10
ack.poolSize=10
#This needs to be in minutes
max.run.time=100
base.dir=\\
Run Code Online (Sandbox Code Playgroud)
来自外部项目的类从我的上下文加载bean: 通过在Eclipse调试模式中检查requestGen对象,我可以看到属性ruleType为null.给定上面的属性文件,ruleType应该是"PAUL"但它是null.
public class App
{
public static void main(Straing[] args)
{
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
RequestGenerator requestGen = context.getBean("requestGenerator", RequestGenerator.class);
Run Code Online (Sandbox Code Playgroud)
该@Value注释被处理由AutowiredAnnotationBeanPostProcessor哪个如果你有一个通常注册<component-scan>或<annotation-config>在XML配置(或直接与bean定义).您需要添加其中任何一个,可能<annotation-config>因为您已经说过没有任何@Component课程.
| 归档时间: |
|
| 查看次数: |
18361 次 |
| 最近记录: |