java - Autowire NullPointerException -


i getting nullpointerexception @ @autowired annotation.

i have added <context:annotation-config/> in spring-context.xml , sessionfactory bean id 'sessionfactory'.

<bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean">   @autowired private sessionfactory sessionfactory; 

can tell root cause.


stack:

java.lang.nullpointerexception @ customerdao.findall(customerdao.java:20) @ customerservice.getcustomers(customerservice.java:19) @ customerresource.listcustomers(customerresource.java:21) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) 

spring bean defination xml:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans.xsd    http://www.springframework.org/schema/context    http://www.springframework.org/schema/context/spring-context.xsd    http://www.springframework.org/schema/mvc    http://www.springframework.org/schema/mvc/spring-mvc.xsd    http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx.xsd">  <context:component-scan base-package="<package-name>"></context:component-scan> <mvc:annotation-driven></mvc:annotation-driven>  <!-- allow static resource handled servelet container --> <mvc:default-servlet-handler />  <context:annotation-config/> <context:property-placeholder location="classpath:backend.properties" />  <!-- spring orm -->  <!--********** mysql spring data source ********** --> <bean id="mysqlsource"     class="org.springframework.jdbc.datasource.drivermanagerdatasource">     <property name="driverclassname" value="${mysql.jdbc.driverclassname}"></property>     <property name="url"         value="jdbc:mysql://${mysql.jdbc.host}:${mysql.jdbc.port}/${mysql.jdbc.databasename}?autoreconnect=true&amp;useunicode=true&amp;characterencoding=utf-8" />     <property name="username" value="${mysql.jdbc.username}" />     <property name="password" value="${mysql.jdbc.password}" /> </bean>   <!--********** sessionfactory **********--> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean">     <property name="datasource" ref="mysqlsource"></property>      <property name="packagestoscan" value="<package-name>.model" />     <property name="hibernateproperties">         <props>             <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop>             <prop key="hibernate.jdbc.batch_size">20</prop>             <prop key="hibernate.show_sql">true</prop>             <prop key="hibernate.connection.setbigstringtryclob">true</prop>             <prop key="hibernate.hbm2ddl.auto">validate</prop>         </props>     </property> </bean> 


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -