Thursday, 27 March 2014

Getting Spring ApplicationContext

This post list down the steps to get Sprint ApplicationContext

1. Create a class ApplicationContextProvider

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware {
    private static ApplicationContext context;

    public static ApplicationContext getApplicationContext() {
        return context;

    public void setApplicationContext(ApplicationContext ctx) {
        context = ctx;

2. Declare a bean in applicationContext.xml
    <bean id="applicationContextProvider" class=""/>

3. Get the ApplicationContext
        context = ApplicationContextProvider.getApplicationContext();

No comments:

Post a Comment