【发布时间】:2013-09-09 20:04:40
【问题描述】:
class ConfigurationDetails {
private @Resource String esHostURL;
private @Resource int maxMessageCounter;
private @Resource String queueName;
// Assume : This class has all getter and setter methods and a default constructor
}
另一个类
public class SpringMessageListener implements MessageListener {
@Resource ConfigurationDetails configDetails; // With getter and setter method for this
............
..........
在我的 XML 中
<bean id="aListener" class="com.vzw.es.cosumer.SpringMessageListener" autowire="byName"/>
<bean id="configDetails" class="com.vzw.es.pojo.ConfigurationDetails" autowire="byName">
<property name="esHostURL" value="http://obsgracstg-db0.odc.vzwcorp.com:9200"/>
<property name="maxMessageCounter" value="500"/>
<property name="queueName" value="ES_queue"/>
</bean>
现在,当我调试代码并看到 SpringMessageListerner 类中的 configDetails 显示为 null 时,id 为 configDetails 的 bean 没有获得自动装配的含义。但是当我明确执行 appContext.getBean("configDetails") 时,它给了我非空对象。
为什么自动装配不起作用?我错过了什么吗?
【问题讨论】:
-
向我们展示您的
component-scan。 -
我的 XML 中没有任何组件扫描元素
-
在这里添加我的整个 XML
-
我无法在此处添加整个 XML,但对于我项目中的另一个 bean,它运行良好,即 RabbitAdmin