Issue 1:
Christian Ihle opened SPR-6656 and commented

ScheduledAnnotationBeanPostProcessor.onApplicationEvent is first run when the Root WebApplicationContext initializes. Then run again when the FrameworkServlet initializes. Each time onApplicationEvent runs a new schedule is registered.

I have modified the task-basic sample from https://src.springframework.org/svn/spring-samples/task-basic/trunk/ to run as a web application for verification. Will attach the source and war file.

This is the console output of task-basic in jetty. It's the same in tomcat. Notice the "processing next 10..." text that shows up twice every 30 seconds. When the application runs from a main class outside a web server the "processing next 10..." text only shows up once every 30 seconds.

2010-01-08 10:38:22.612::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2010-01-08 10:38:22.738::INFO: jetty-6.1.17
2010-01-08 10:38:23.212:/task-basic:INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri Jan 08 10:38:23 CET 2010]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/springframework/samples/task/basic/annotation/config.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@144b9ff: defining beans [scheduledProcessor,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.scheduling.annotation.internalAsyncAnnotationProcessor,org.springframework.scheduling.annotation.internalScheduledAnnotationProcessor]; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 13801 ms
processing next 10 at Fri Jan 08 10:38:37 CET 2010
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'SpringServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'SpringServlet-servlet': startup date [Fri Jan 08 10:38:37 CET 2010]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/servlet-context.xml]
2010-01-08 10:38:37.139:/task-basic:INFO: Initializing Spring FrameworkServlet 'SpringServlet'
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@fffa61: defining beans []; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@144b9ff
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'SpringServlet': initialization completed in 4407 ms
processing next 10 at Fri Jan 08 10:38:41 CET 2010
2010-01-08 10:38:41.557::INFO: Opened C:\Users\Christian\Programmer\jetty-6.1.17\logs\2010_01_08.request.log
2010-01-08 10:38:41.641::INFO: Started SelectChannelConnector@0.0.0.0:8080
processing next 10 at Fri Jan 08 10:39:07 CET 2010
processing next 10 at Fri Jan 08 10:39:11 CET 2010
processing next 10 at Fri Jan 08 10:39:37 CET 2010
processing next 10 at Fri Jan 08 10:39:41 CET 2010

Affects: 3.0 GA

Reference URL: http://forum.springsource.org/showthread.php?t=80225

Attachments:

org.springframework.samples.task.basic-1.0.0-SNAPSHOT.war (3.11 MB)

task-basic.zip (11.41 kB)

Issue Links:

#11329 @Scheduled tasks scheduled multiple times when a child application context is refreshed ("is duplicated by")

#11525 Scheduled tasks seem to run twice ("is duplicated by")

#16655 JmsListener/ScheduledAnnotationBeanPostProcessor should use SmartInitializingSingleton instead of ContextRefreshedEvent

Referenced from: commits 4ca54fb

Issue 2:
Jerry Carter opened SPR-6596 and commented

The documentation for 3.0 does not illustrate a parameterized 'ApplicationListener'. Assuming that the 2.5.x method applies, we find that events are not filtered prior to invoking the ApplicationListener and that, as a result, parameterized listeners cannot be used in 3.0.0.

The ApplicationListener bean is registered in the applicationContext.xml as per usual:

<bean id="sessionEvents" class="org.example.SessionEventListener"/>

The code established the appropriate callback:

public class SessionEventListener implements ApplicationListener<AbstractAuthenticationEvent> {
public void onApplicationEvent(AbstractAuthenticationEvent authEvent) {
...
}
}

But the events are not properly converted.

java.lang.IllegalStateException: Failed to load ApplicationContext

at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)

at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)

at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)

at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.ClassCastException: org.springframework.context.event.ContextRefreshedEvent cannot be cast to org.springframework.security.event.authentication.AbstractAuthenticationEvent

at org.example.SessionEventListener.onApplicationEvent(SessionEventListener.java:29)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)

at $Proxy32.onApplicationEvent(Unknown Source)

at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)

at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:294)

at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:858)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:419)

at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)

at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)

at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)

at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)

... 24 more

Affects: 3.0 GA

Issue Links:

#11337 ClassCastException on EventListener invocation when proxies come into play ("is duplicated by")