Last active
August 29, 2015 14:05
-
-
Save sambos/434a7ec74d343ec5629b to your computer and use it in GitHub Desktop.
How to load Spring Application Context in TC Server using ApplicationContextAware
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
public class AppContext { | |
private static ApplicationContext ctx; | |
public static void setApplicationContext(ApplicationContext applicationContext) { | |
ctx = applicationContext; | |
} | |
public static ApplicationContext getApplicationContext() { | |
return ctx; | |
} | |
} |
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
<bean id="contextApplicationContextProvider" class="sf.poc.spring.ApplicationContextProvider"></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
public class ApplicationContextProvider implements ApplicationContextAware { | |
public void setApplicationContext(ApplicationContext ctx) throws BeansException { | |
// Wiring the ApplicationContext into a static method | |
AppContext.setApplicationContext(ctx); | |
} | |
} |
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
Retrieve... | |
----------------------- | |
ApplicationContext ctx = AppContext.getApplicationContext(); | |
((MessageUtil)ctx.getBean("msgUtil")).getMessage(); |
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
<context-param> | |
<param-name>contextConfigLocation</param-name> | |
<param-value>/WEB-INF/applicationContext.xml</param-value> | |
</context-param> | |
<listener> | |
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | |
</listener> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment