In spring it is possible to do this. Does anybody have code samples?
+1
A:
if (number % 2 == 0) { // is even
anotherBean = (AnotherBean) applicationContext.getBean("anotherBean");
// send even to another bean
anotherBean.send(number);
}
For additional information, see here.
James Earl Douglas
2010-08-30 04:23:16
what's the conditional for?
Bozho
2010-08-30 07:05:20
It was a joke, as the question asked "how to send an even to another bean".
James Earl Douglas
2010-08-30 15:56:23
+1
A:
If you want to notify a bean about something, simply call a method:
@Service
public class Notifier {
@Autowired
private Notified notified;
public void something() {
notified.notify(..);
}
}
But event handling is usually asynchronous. In that case you will have to create a new Thread
(or use the executors framework since Java 5), pass a reference to / inject the target bean, and let it notify it.
And if instead you want to notify multiple beans, without knowing which exactly, then use the event mechanism that spring provides as an implementation of the observer pattern.
Bozho
2010-08-30 05:55:11
+1
A:
You can use Spring Integration for messaging between beans in your context. Look at MessageChannel and ServiceActivator. You can route, filter, split messages to your beans how ever you need.
Adam B
2010-08-31 20:02:18