January 05, 2010

ApplicationContextAware - access application context from bean

« Spring scope | Main | OpenJDK or Java Sun JDK on Ubuntu »
Sometimes you need to access your Spring application context from a Spring instrumentalized Bean. For this use case you need to implement the ApplicationContextAware interface. The following code snippets desribes the usage:

Implementation class:
public class ApplicationContextProvider implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

}
Spring configuration:
<bean id="applicationContextProvider" class="org.developers.blog.spring.examples.ApplicationContextProvider"></bean>
Regards
Rafael Sobek

Technorati Tags:

Posted by rafael.sobek at 11:48 AM in Spring

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« January »
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31