Boolean variable has to be shared in diff spring bean
I have two beans
<bean id="eventService" class="xxx.xxxx.xxxxx.EventServiceImpl">
</bean>
<bean id="UpdateService" class="xxx.xxxx.xxxxx.UpdateServiceImpl">
</bean>
A Boolean variable has to be shared... means updating Boolean in a bean should be available for other bean to 开发者_如何学Pythonknow the status
appreciate your idea guys
The fact that you have multiple objects interested in a the same flag sounds very much like an event. Have a look at Spring's support from broadcasting and listening to events (including custom events).
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#context-functionality-events
What you could do is have one managed object be the "owner" of that flag, and broadcast state changes to anyone else that's interested via an event.
I'm afraid you will need some value holder bean, something like this:
public class ValueHolder{
private boolean flag;
public boolean isFlag(){return flag;}
public void setFlag(boolean flag){this.flag=flag;}
}
Wire this as a Spring Bean and inject it into your service beans.
Just for completeness: or you could use a static field, but that's even uglier.
精彩评论