Created
July 25, 2012 12:44
-
-
Save mdread/3175976 to your computer and use it in GitHub Desktop.
get access to the Spring application context from a non-managed bean
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
import org.springframework.context.ApplicationContext; | |
public class AppContext { | |
private static ApplicationContext context; | |
public static void setApplicationContext(ApplicationContext applicationContext) { | |
context = applicationContext; | |
} | |
public static ApplicationContext getApplicationContext() { | |
return context; | |
} | |
} |
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
import org.springframework.beans.BeansException; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.ApplicationContextAware; | |
import org.springframework.core.Ordered; | |
import org.springframework.core.annotation.Order; | |
import org.springframework.stereotype.Component; | |
@Component | |
@Order(Ordered.HIGHEST_PRECEDENCE) | |
public class ApplicationContextProvider implements ApplicationContextAware { | |
public void setApplicationContext(ApplicationContext ctx) throws BeansException { | |
AppContext.setApplicationContext(ctx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment