Announcement Announcement Module
Collapse
No announcement yet.
Configuring bean event listeners Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring bean event listeners

    I'd like to configure bean event listeners in a class from a legacy library through Spring's XML mechanism. These methods follow the naming convention detailed in the JavaBeans specification. Namely, add*Listener and remove*Listener. I haven't been able to find any references to this in relation to Spring, so I'm asking here for some hints.

    Currently I'm calling a factory method from an init-method:
    Code:
    	<bean id="..." class="..."
    		scope="prototype" init-method="init">
    		<lookup-method name="createMyHandler" bean="myHandler" />
    		<property name="legacyObj" bean="legacyObj" />
    		...
    
    	<bean id="legacyObj" class="LegacyObject" scope="prototype">
    	</bean>
    Code:
    	public void init() {
    		legacyObj.addMyListener(createMyHandler());
    	}
    
    	protected abstract MyListener createMyHandler();
    I'd rather avoid the boilerplate code and mingling with init-method by adding the myHandler bean to the myListener collection from the XML in the definition of legacyObj. Is this possible? What do you suggest? I'm thinking of something along the lines of:
    Code:
    	<bean id="..." class="..." scope="prototype">
    		<property name="legacyObj" bean="legacyObj" />
    		...
    
    	<bean id="legacyObj" class="LegacyObject" scope="prototype">
    		<property name="myListener">
    			<set>
    				<ref bean="myHandler" />
    			</set>
    		</property>
    	</bean>
    Last edited by jkohen; Jun 25th, 2007, 06:17 PM.

  • #2
    Are you saying you are looking for a way to call adder methods from Spring?
    http://forum.springframework.org/showthread.php?t=31058
    Last edited by karldmoore; Aug 29th, 2007, 12:56 PM.

    Comment


    • #3
      So I'll wait...

      Looking at SPR-230, then I guess the only thing I can do for now is wait for Spring 2.2 to be released.

      Thanks for taking the time to answer.

      Comment


      • #4
        You can obivously work around it by providing your own adder functionality in the code for the time being. If you follow the threads it lots like there were quite a few suggestions.
        Last edited by karldmoore; Aug 29th, 2007, 12:56 PM.

        Comment

        Working...
        X