Hi,
I have a large number of beans defined in a spring config file A.xml, and I import them in file B.xml.
One bean in A.xml can no longer be instantiated in the new environment that I am using it in. e.g. it requires a JNDI lookup for a data source, and my current test application is a standalone one, which doesn't have a JNDI directory since it isn't running in a server.
So I override the bean definition by providing another bean in B.xml with same id as that in A.xml. This doesn't seem to work, and I have the following error:
-----------------
Error creating bean with name 'gen.db.datasource' defined in class path resource [com/def/abc/gen/db-spring-config.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(N amingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(Init ialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx (InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext. java:351)
at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:124)
at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:86)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:122)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.java:147)
at org.springframework.jndi.JndiLocatorSupport.lookup (JndiLocatorSupport.java:90)
at org.springframework.jndi.JndiObjectLocator.lookup( JndiObjectLocator.java:101)
at org.springframework.jndi.JndiObjectFactoryBean.loo kupWithFallback(JndiObjectFactoryBean.java:164)
at org.springframework.jndi.JndiObjectFactoryBean.aft erPropertiesSet(JndiObjectFactoryBean.java:151)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 45)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:141)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:287)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:348)
at org.springframework.context.support.ClassPathXmlAp plicationContext.(ClassPathXmlApplicationContext.j ava:92)
at org.springframework.context.support.ClassPathXmlAp plicationContext.(ClassPathXmlApplicationContext.j ava:77)
at org.springframework.context.support.ClassPathXmlAp plicationContext.(ClassPathXmlApplicationContext.j ava:68)
------------------
How do I override a bean definition in A.xml while still using all the other beans in A.xml ?
I will appreciate any help from the spring user community.
Thanks,
Sunil Jigyasu


Reply With Quote
