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;
}
@Override
public void setApplicationContext(ApplicationContext ctx) {
context = ctx;
}
}
2. Declare a bean in applicationContext.xml
<bean id="applicationContextProvider" class="aa.bb.cc.ApplicationContextProvider"/>
3. Get the ApplicationContext
context = ApplicationContextProvider.getApplicationContext();
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;
}
@Override
public void setApplicationContext(ApplicationContext ctx) {
context = ctx;
}
}
2. Declare a bean in applicationContext.xml
<bean id="applicationContextProvider" class="aa.bb.cc.ApplicationContextProvider"/>
3. Get the ApplicationContext
context = ApplicationContextProvider.getApplicationContext();
No comments:
Post a Comment