質問

I can autowire two QueueChannel instances using @Autowired and @Qualifier in a test class just fine, until I add JMX export namespace handlers.

I've not got the exact config handy (it was a problem at work that's now bugging me out of hours!), but I'm using these elements:

<int-jmx:mbean-export default-domain="com.business" server="mbeanServer" />
<context:mbean-export />
<context:mbean-server />

When I've got these three things defined, the autowiring process fails throwing a NoSuchBeanException. However, I can see that there are beans with the IDs of my queues, as I've got a post processor that's iterating over all beans in the context.

Is this something to do with proxying obfuscating the declared type of the QueueChannels, preventing autowiring-by-type working?

役に立ちましたか?

解決

You need to autowire using the interface instead of the concrete class because the JMX export wraps the channel in a proxy. Use PollableChannel for QueueChannel, or SubscribableChannel for DirectChannel.

It's always good practice to code using interfaces rather than concrete classes, for exactly this reason.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top