[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 Jun 20 18:13:20 EDT 2007
Only BeanFactories that are constructed by SpringDeployer can reference beans from parent BeanFactories.
In your case parent BF is constructed by SpringDeployer, but your child BF is constructed by regular Spring ContextLoader.
And only SpringDeployer knows about parent=(<some_parent>) notion.
You can use something like this:
| public abstract class AbstractJndiContextLoader extends ContextLoader {
|
| protected String getJndiName(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);
| }
| return jndiName;
| }
|
| protected Context createContext() throws BeansException {
| try {
| return new InitialContext();
| } catch (Exception e) {
| throw new ApplicationContextException("Cannot create naming context!", e);
| }
| }
|
| }
|
| public abstract class JndiContextSaver extends AbstractJndiContextLoader {
|
| @Override
| protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent) throws BeansException {
| try {
| WebApplicationContext wac = super.createWebApplicationContext(servletContext, parent);
| bindApplicationContext(getJndiName(servletContext), wac);
| return wac;
| } catch (Exception e) {
| throw new ApplicationContextException("Cannot bind application context.", e);
| }
| }
|
| protected abstract void bindApplicationContext(String jndiName, ApplicationContext applicationContext) throws Exception;
|
| @Override
| public void closeWebApplicationContext(ServletContext servletContext) {
| unbindApplicationContext(getJndiName(servletContext));
| super.closeWebApplicationContext(servletContext);
| }
|
| protected abstract void unbindApplicationContext(String jndiName);
|
| }
|
| public class JBossJndiContextSaver extends JndiContextSaver {
|
| protected void bindApplicationContext(String jndiName, ApplicationContext applicationContext) throws Exception {
| NonSerializableFactory.bind(createContext(), jndiName, applicationContext);
| }
|
| protected void unbindApplicationContext(String jndiName) {
| try {
| NonSerializableFactory.unbind(createContext(), jndiName);
| } catch (NamingException e) {
| LogFactory.getLog(getClass()).warn("Exception unbinding application context.", e);
| }
| }
|
| }
|
| public class JndiContextSaverListener extends InitializerContextLoaderListener {
|
| @Override
| protected ContextLoader createContextLoader() {
| return new JBossJndiContextSaver();
| }
|
| }
|
| <listener>
| <listener-class>com.alesj.acme.webcommon.context.JndiContextSaverListener</listener-class>
| </listener>
|
|
HTH,
Ales
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056211#4056211
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056211
More information about the jboss-user
mailing list