Don't use ApplicationContext to publish events. Create a 'Notifier' class, implement ApplicationContextAware and ApplicationEventPublisher.
In the publishEvent method simply passthrough to the ApplicationEventPublisher method.
Always use this class to publish events in your application.
use the 'publishEvent' method and the ApplicationEventPublisher interface in your TransactionProxyFactoryBean.
For example:
public class Notifier implements ApplicationContextAware, ApplicationEventPublisher {
ApplicationContext context;
DataAccess dao;
public Notifier(DataAccess dao) {
this.dao = dao;
}
public void setApplicationContext(ApplicationContext context) throws BeansException {
this.context = context;
}
public void publishEvent(ApplicationEvent event) {
context.publishEvent(event);
}
}
-------------
<bean id="notifierTarget" class="nz.co.syntax.Notifier">
<constructor-arg ref="dao"/>
</bean>
<bean id="notifier" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyInterfaces" value="org.springframework.context.ApplicationEven tPublisher"/>
<property name="target" ref="notifierTarget"/>
<property name="transactionAttributes">
<props>
<prop key="publishEvent"> PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED
</prop>
</props>
</property>
</bean>
------------
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
ApplicationEventPublisher publisher = (ApplicationEventPublisher) ctx.getBean("notifier");
publisher.publishEvent(...);
cheers
Dave
Dave Jenkins
Wellington
New Zealand