我遵循了 spring 文档并设置了一个 Spring JMS 侦听器。然而,即使我向队列中添加了一条消息,我的代码也没有检测到这一点。我的弹簧配置如下:
<bean id="dataSourceListener" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="xxx"/>
<property name="user" value="xxx"/>
<property name="password" value="xxx"/>
</bean>
<bean id="jmsConnectionFactory" class="OracleAqFactoryBean">
<property name="dataSource" ref="dataSourceListener" />
</bean>
<jms:listener-container connection-factory="jmsConnectionFactory" acknowledge="transacted" concurrency="1-5">
<jms:listener destination="queuename" ref="myMessageListener"/>
</jms:listener-container>
<bean id="myMessageListener" class="Listener"/>
我的Java如下:
我的自定义监听器:
class Listener implements MessageListener {
@Override
void onMessage(Message message) {
// code to handle message is here
}
}
还有我的 OracleAqFactoryBean:
public class OracleAqFactoryBean implements FactoryBean {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public Object getObject() throws Exception {
return AQjmsFactory.getConnectionFactory( dataSource );
}
@Override
public Class<?> getObjectType() {
return ConnectionFactory.class;
}
@Override
public boolean isSingleton() {
return true;
}
}
[编辑:上述设置现已成功运行]