[jboss-user] [JBoss/Spring Integration] - Re: Accessing app_1's spring beans in app_2's config file
alesj
do-not-reply at jboss.com
Wed Mar 12 09:10:26 EDT 2008
The missing code:
| public class InitializerContextLoaderListener extends ContextLoaderListener {
|
| @Override
| public void contextInitialized(ServletContextEvent event) {
| JndiRootApplicationContextLookup.initialize(event.getServletContext());
| super.contextInitialized(event);
| }
|
| }
|
| public class JndiRootApplicationContextLookup {
|
| private static final Log log = LogFactory.getLog(JndiRootApplicationContextLookup.class);
| public static final String ROOT_JNDI_APP_CONTEXT_KEY = "RootJndiApplicationContextKey";
| public static final String DEFAULT_ROOT_APP_CONTEXT_JNDI_NAME = "RootJndiApplicationContextName";
|
| private static String JNDI_NAME;
|
| public static String jndiName() {
| return JNDI_NAME;
| }
|
| public static void initialize(ServletContext servletContext) {
| String jndiName = DEFAULT_ROOT_APP_CONTEXT_JNDI_NAME;
| if (servletContext.getInitParameter(ROOT_JNDI_APP_CONTEXT_KEY) != null) {
| jndiName = servletContext.getInitParameter(ROOT_JNDI_APP_CONTEXT_KEY);
| }
| if (JNDI_NAME != null && !JNDI_NAME.equals(jndiName)) {
| log.warn("Jndi name already initialized with different name: " + JNDI_NAME + " / " + jndiName);
| }
| JNDI_NAME = jndiName;
| }
|
| public static Object lookup(String beanName) throws Exception {
| JndiTemplate jndiTemplate = new JndiTemplate();
| ApplicationContext ac = (ApplicationContext) jndiTemplate.lookup(JNDI_NAME, ApplicationContext.class);
| return ac.getBean(beanName);
| }
|
| }
|
Try it now, and let me know.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4135917#4135917
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4135917
More information about the jboss-user
mailing list