Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#context-functionality-events"><strong>Spring has some standard events which you can handle.</strong></a> </p> <p>To do that, you must create and register a bean that implements the <code>ApplicationListener</code> interface, something like this:</p> <pre><code>package test.pack.age; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; public class ApplicationListenerBean implements ApplicationListener { @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); // now you can do applicationContext.getBean(...) // ... } } } </code></pre> <p>You then register this bean within your <code>servlet.xml</code> or <code>applicationContext.xml</code> file:</p> <pre><code>&lt;bean id="eventListenerBean" class="test.pack.age.ApplicationListenerBean" /&gt; </code></pre> <p>and Spring will notify it when the application context is initialized.</p> <p>In Spring 3 (if you are using this version), the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/ApplicationListener.html"><code>ApplicationListener</code> class is generic</a> and you can declare the event type that you are interested in, and the event will be filtered accordingly. You can simplify a bit your bean code like this:</p> <pre><code>public class ApplicationListenerBean implements ApplicationListener&lt;ContextRefreshedEvent&gt; { @Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext applicationContext = event.getApplicationContext(); // now you can do applicationContext.getBean(...) // ... } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload