You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Initialisation of MessageHandler in MessageHandlerChain [INT-756] #4769
I've tried using a bean that implements MessageHandler and setOutputChannel in a MessageHandlerChain. I've found that I cannot use MyBean.afterPropertiesSet() to check that the outputChannel is set because the method is getting called before the MessageHandlerChain is initialised (which sets the outputChannel on it's messageHandlers).
We might need to create and register BeanDefinitions for the internal MessageChannels when parsing the 'chain' rather than setting these programmatically. If possible, we should address for 1.0.4 (and 2.0)
I've experimented with a few options here, but the order of events and the relationship to lifecycle methods is a cyclical problem. In other words, the MessageHandlerChain instance is the one that has the list of handlers set. So, when configuring as beans, the individual handler beans are instantiated (and have their dependencies set) first. The afterPropertiesSet method for each would therefore be called even before those beans are set on the chain bean. The chain then only after receiving the list of handlers creates and sets the output channels.
There might be a way to control this by creating the channels within the configuration alongside the parsing of the individual handler beans. Then, with the entire process driven at configuration time, it would be possible to set the properties (including input/output channels) on the bean definition. The main problem with that approach is that it would then preclude the possibility of simply instantiating a MessageHandlerChain at runtime and setting a list of handlers on it directly.
Can you describe more about your need to check the output channel in afterPropertiesSet? Assuming that the MessageHandlerChain is being used and does not have a bug, then the output channel will be set. Is there some other action that you want to drive based on that?
Apologies for delayed feedback. I did in fact email this back in October and thought it would auto-update.
I'd like to use my bean outside of a chain - in which case I'd like to verify my channel is set. However this isn't a show stopper for me personally - HandlerChain is a nice way of cutting down the config.
I'm resolving this as won't fix simply because the connection of MessageHandlers within a chain is deferred until the chain itself is initialized. If the handlers within that chain are themselves InitializingBean implementations, then afterPropertiesSet() will always be called on those beans before the chain configuration occurs.
The chain configuration itself has been simplified considerably in 2.0 M3 however. See #4926 and #4985 for some more information.
Feel free to comment here if there is a strong reason for the originally requested resolution. Perhaps there is a better way to address it.
Activity
spring-operator commentedon Aug 20, 2009
Mark Fisher commented
We might need to create and register BeanDefinitions for the internal MessageChannels when parsing the 'chain' rather than setting these programmatically. If possible, we should address for 1.0.4 (and 2.0)
spring-operator commentedon Oct 1, 2009
Mark Fisher commented
I've experimented with a few options here, but the order of events and the relationship to lifecycle methods is a cyclical problem. In other words, the MessageHandlerChain instance is the one that has the list of handlers set. So, when configuring as beans, the individual handler beans are instantiated (and have their dependencies set) first. The afterPropertiesSet method for each would therefore be called even before those beans are set on the chain bean. The chain then only after receiving the list of handlers creates and sets the output channels.
There might be a way to control this by creating the channels within the configuration alongside the parsing of the individual handler beans. Then, with the entire process driven at configuration time, it would be possible to set the properties (including input/output channels) on the bean definition. The main problem with that approach is that it would then preclude the possibility of simply instantiating a MessageHandlerChain at runtime and setting a list of handlers on it directly.
Can you describe more about your need to check the output channel in afterPropertiesSet? Assuming that the MessageHandlerChain is being used and does not have a bug, then the output channel will be set. Is there some other action that you want to drive based on that?
spring-operator commentedon Oct 1, 2009
Mark Fisher commented
Moving to 2.0-M2 (but still targeting 1.0.4 as well) until feedback is received and/or we consider another way to support the requested functionality.
spring-operator commentedon Nov 23, 2009
Nigel Watson commented
Apologies for delayed feedback. I did in fact email this back in October and thought it would auto-update.
I'd like to use my bean outside of a chain - in which case I'd like to verify my channel is set. However this isn't a show stopper for me personally - HandlerChain is a nice way of cutting down the config.
spring-operator commentedon Dec 11, 2009
Mark Fisher commented
Moving to 2.0-M3 since we'll want to consider this in light of #4926.
spring-operator commentedon Mar 9, 2010
Mark Fisher commented
I'm resolving this as won't fix simply because the connection of MessageHandlers within a chain is deferred until the chain itself is initialized. If the handlers within that chain are themselves InitializingBean implementations, then afterPropertiesSet() will always be called on those beans before the chain configuration occurs.
The chain configuration itself has been simplified considerably in 2.0 M3 however. See #4926 and #4985 for some more information.
Feel free to comment here if there is a strong reason for the originally requested resolution. Perhaps there is a better way to address it.