我正在使用 Spring 3.1
我已经配置了监听它的 HornetQ 和 MDB。
我的目标是向那些 MDBS 注入一个具有独特属性的属性类。
每个 MDB 都有自己的属性
我一尝试就得到异常。
那是我的代码:
多边开发银行:
public class FeedListenerMDB implements MessageListener
{
private final static Logger log = Logger.getLogger(FeedListenerMDB.class);
FeedPropertiesDTO feedPropertiesDTO;
...
@Override
public void onMessage(Message message)
{
if (message instanceof TextMessage)
{
try
{
String text = ((TextMessage) message).getText();
log.debug("i am marketmaker=" + feedPropertiesDTO.getMarketMakerId() + " and the message I got=" + text);
}
catch (JMSException ex)
{
throw new RuntimeException(ex);
}
}
else
{
throw new IllegalArgumentException("Message must be of type TextMessage");
}
}
}
那就是 FeedPropertiesDTO :
public class FeedPropertiesDTO
{
private String marketMakerId;
public String getMarketMakerId()
{
return marketMakerId;
}
public void setMarketMakerId(String marketMakerId)
{
this.marketMakerId = marketMakerId;
}
}
现在这是我的应用程序上下文 bean 设置:
<bean id="FeedListenerMarketMaker1MDB" class="com.fixgw.mdb.FeedListenerMDB">
<property name="feedPropertiesDTO" ref="feedListenerMarketMaker1Properties" />
</bean>
<bean id="feedListenerMarketMaker1Properties" class="com.fixgw.dto.FeedPropertiesDTO">
<property name="marketMakerId" value="1" />
</bean>
<bean id="FeedListenerMarketMaker2MDB" class="com.fixgw.mdb.FeedListenerMDB">
<property name="feedPropertiesDTO" ref="feedListenerMarketMaker2Properties" />
</bean>
<bean id="feedListenerMarketMaker2Properties" class="com.fixgw.dto.FeedPropertiesDTO" >
<property name="marketMakerId" value="2" />
</bean>
通过这种方式,我将能够从 applicationContext 配置我的 MDBS 并在将来添加新的,而无需接触代码。
但我得到这个错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.fixgw.mdb.FeedListenerMDB] is defined: expected single matching bean but found 2: [FeedListenerMarketMaker1MDB, FeedListenerMarketMaker2MDB]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:800)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:551)
... 17 more
知道如何实现我的需要吗?
谢谢,雷。