Skip to content

Instantly share code, notes, and snippets.

@zxlooong
Created November 7, 2014 17:14
Show Gist options
  • Save zxlooong/5095288f6e104ba4a6bd to your computer and use it in GitHub Desktop.
Save zxlooong/5095288f6e104ba4a6bd to your computer and use it in GitHub Desktop.
package cn.liveworks.dev.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* must have this config
* <bean id="auth_contextApplicationContextProvider"
* class="com.wangyin.ssoclient.sso.util.ApplicationContextProvider">
* </bean>
* @author lycy
*
*/
public class ApplicationContextProvider implements
ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
AppContext.setApplicationContext(applicationContext);
}
public static class AppContext{
private static ApplicationContext ctx;
/**
* Injected from the class "ApplicationContextProvider" which is automatically
* loaded during Spring-Initialization.
*/
public static void setApplicationContext(ApplicationContext applicationContext) {
ctx = applicationContext;
}
/**
* Get access to the Spring ApplicationContext from everywhere in your Application.
*
* @return
*/
public static ApplicationContext getApplicationContext() {
return ctx;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment