mercredi 8 avril 2015

Publishing asynchronous event, multiple instances of SimpleApplicationEventMulticaster

I'm trying to publish an asynchronous event in Spring via SimpleApplicationEventMulticaster, but some strange thing is happening.



<bean id="registrationListener" class="com.mycomp.project.event.RegistrationListener" />
<bean id="applicationEventMulticaster"
class="org.springframework.context.event.SimpleApplicationEventMulticaster">
<property name="taskExecutor">
<bean
class="org.springframework.scheduling.quartz.SimpleThreadPoolTaskExecutor">
<property name="threadCount" value="10" />
</bean>
</property>
</bean>


On controller, I'm autowiring it in order to publish events:



@Autowired
@Qualifier(value = "applicationEventMulticaster")
private SimpleApplicationEventMulticaster simpleApplicationEventMulticaster;
//
simpleApplicationEventMulticaster.multicastEvent(new OnRegistrationCompleteEvent(newUser, req.getLocale(), appUrl));


But the autowired one is not the one defined in context. On the listener public class RegistrationListener implements ApplicationListener<OnRegistrationCompleteEvent>{} autowiring the same SimpleApplicationEventMulticaster shows the right instance configured in context.


From my observation, there are two instances of SimpleApplicationEventMulticaster, one created by me and one implicitly by Spring. Basically the listener seems to be registered on the default one created by Spring.


Any idea what's happening?


Thanks


Aucun commentaire:

Enregistrer un commentaire