PDA

View Full Version : unable to define Bean Scope in Spring 2.5



anupam_kum
Oct 8th, 2009, 02:05 AM
<code>
<bean id="countryList" class="com.spring.sample.domain.CountryList" scope="globalSession"/>

<bean id="userService" class="com.spring.sample.service.UserServiceImpl">
<property name="countryList"><ref bean="countryList"/></property>
</bean>
</code>

but i am getting following error
ERROR [http-8080-2] (FrameworkServlet.java:290) Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF//HospitalMgmt-config/HospitalMgmt-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.spring.sample.service.UserServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:729)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:381)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:4 02)
at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:316 )
at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:808)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.spring.sample.service.UserServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:115)
at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:61)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:877)
... 30 more
Caused by: java.lang.NullPointerException
at com.spring.sample.service.UserServiceImpl.<init>(UserServiceImpl.java:21)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:100)
... 32 more
20781 [http-8080-2] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF//HospitalMgmt-config/HospitalMgmt-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [com.spring.sample.service.UserServiceImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:221)
at org.spri

Please provide me way to resolve this.

Regards,
Anupam Kumar.

anupam_kum
Oct 8th, 2009, 03:50 AM
Adding to this i also added
<listener>
<listener-class>org.springframework.web.context.request.RequestCon textListener</listener-class>
</listener>

in web.xml.

Please resolve this ASAP.


Regards,
Anupam Kumar.
+91-98862-74713