Reputation: 5060
Given these two beans:
myMessageAdapter(MessageListenerAdapter) { bean ->
bean.constructorArgs = [ref('jmsReceiver')]
defaultListenerMethod = 'processMessage'
}
listenerContainer(DefaultMessageListenerContainer) {
connectionFactory = ref('connectionFactory')
destinationName = "MyDest"
messageListener = ref('myMessageAdapter')
}
I would like to replace myMessageAdapter
with an anonymous inner bean.
Tried:
listenerContainer(DefaultMessageListenerContainer) {
connectionFactory = ref('connectionFactory')
destinationName = "MyDest"
messageListener = { MessageListenerAdapter bean ->
bean.constructorArgs = [ref('jmsReceiver')]
defaultListenerMethod = 'processMessage'
}
}
But it fails with "Cannot set property 'constructorArgs' on null object"
How can I pass the constructor param?
Upvotes: 0
Views: 230
Reputation: 68
The way you can achieve this is to set the class within the bean closure:
listenerContainer(DefaultMessageListenerContainer) {
connectionFactory = ref('connectionFactory')
destinationName = "MyDest"
messageListener = { bean ->
bean.beanClass = MessageListenerAdapter
bean.constructorArgs = [ref('jmsReceiver')]
bean.defaultListenerMethod = 'processMessage'
}
}
Upvotes: 1
Reputation: 191
I don't think it's possible when you look at the source code for the BeanBuilder and the method setPropertyOnBeanConfig
Upvotes: 1