<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=blurpy" rel="nofollow">Christian Ihle</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6656?redirect=false" rel="nofollow">SPR-6656</a></strong> and commented</p>
<p dir="auto">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.</p>
<p dir="auto">I have modified the task-basic sample from <a href="https://src.springframework.org/svn/spring-samples/task-basic/trunk/" rel="nofollow">https://src.springframework.org/svn/spring-samples/task-basic/trunk/</a> to run as a web application for verification. Will attach the source and war file.</p>
<p dir="auto">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.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 GA</p>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?t=80225" rel="nofollow">http://forum.springsource.org/showthread.php?t=80225</a></p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/16075/org.springframework.samples.task.basic-1.0.0-SNAPSHOT.war" rel="nofollow">org.springframework.samples.task.basic-1.0.0-SNAPSHOT.war</a> (<em>3.11 MB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/16074/task-basic.zip" rel="nofollow">task-basic.zip</a> (<em>11.41 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398101674" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11329" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11329/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11329">#11329</a> <code class="notranslate">@Scheduled</code> tasks scheduled multiple times when a child application context is refreshed (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398103048" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11525" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11525/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11525">#11525</a> Scheduled tasks seem to run twice (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398170332" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/16655" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/16655/hovercard" href="https://github.com/spring-projects/spring-framework/issues/16655">#16655</a> JmsListener/ScheduledAnnotationBeanPostProcessor should use SmartInitializingSingleton instead of ContextRefreshedEvent</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/4ca54fb4158da6337060cac9faba6911f192aa1e/hovercard" href="https://github.com/spring-projects/spring-framework/commit/4ca54fb4158da6337060cac9faba6911f192aa1e"><tt>4ca54fb</tt></a></p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=jerry@jerrycarter.org" rel="nofollow">Jerry Carter</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6596?redirect=false" rel="nofollow">SPR-6596</a></strong> and commented</p>
<p dir="auto">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.</p>
<p dir="auto">The ApplicationListener bean is registered in the applicationContext.xml as per usual:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;sessionEvents&quot; class=&quot;org.example.SessionEventListener&quot;/&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="sessionEvents" class="org.example.SessionEventListener"/&gt;
</code></pre></div>
<p dir="auto">The code established the appropriate callback:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class SessionEventListener implements ApplicationListener&lt;AbstractAuthenticationEvent&gt; {
    public void onApplicationEvent(AbstractAuthenticationEvent authEvent) {
        ...
    }
}"><pre class="notranslate"><code class="notranslate">public class SessionEventListener implements ApplicationListener&lt;AbstractAuthenticationEvent&gt; {
    public void onApplicationEvent(AbstractAuthenticationEvent authEvent) {
        ...
    }
}
</code></pre></div>
<p dir="auto">But the events are not properly converted.</p>
<p dir="auto">java.lang.IllegalStateException: Failed to load ApplicationContext<br>
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)<br>
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)<br>
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)<br>
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)<br>
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)<br>
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)<br>
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)<br>
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)<br>
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)<br>
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)<br>
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)<br>
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)<br>
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)<br>
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)<br>
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)<br>
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)<br>
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)<br>
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)<br>
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)<br>
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)<br>
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)<br>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)<br>
Caused by: java.lang.ClassCastException: org.springframework.context.event.ContextRefreshedEvent cannot be cast to org.springframework.security.event.authentication.AbstractAuthenticationEvent<br>
at org.example.SessionEventListener.onApplicationEvent(SessionEventListener.java:29)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:597)<br>
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)<br>
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)<br>
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)<br>
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)<br>
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)<br>
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)<br>
at $Proxy32.onApplicationEvent(Unknown Source)<br>
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)<br>
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:294)<br>
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:858)<br>
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:419)<br>
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:84)<br>
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)<br>
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)<br>
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)<br>
... 24 more</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 GA</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398101749" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11337" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11337/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11337">#11337</a> ClassCastException on EventListener invocation when proxies come into play (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>