Created
November 7, 2014 17:14
-
-
Save zxlooong/5095288f6e104ba4a6bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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