Thursday, 15 July 2010

spring - @Autowired in JAX-RS resource returning null value -



spring - @Autowired in JAX-RS resource returning null value -

i ruining code time auto-wired object returning null.

requestservicesimpl

@component @path("requests") public class requestservicesimpl { private requestdao request; @autowired public void setpersonservice(requestdao cs){ this.request = cs; } @get @path("getrequests") @produces(mediatype.application_json) public requesttransfer[] getrequests() { string msg = null; notestransfer note=new notestransfer(0, 0, msg, msg, msg); requesttransfer[] requestaray=new requesttransfer[1]; requestaray[0] =new requesttransfer(0, msg, msg, msg, msg); requestaray[0].setnotes(note); // todo auto-generated method stub string output = "jersey : " ; request.listrequest(); requestprocessimpl requstprocess=new requestprocessimpl(); requstprocess.fetchclientrequests(); system.out.println("------------"+output+"--------------"); homecoming requestaray; }

context.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> <context:component-scan base-package="com.cherry.servicedesk.rest.service" /> <!-- scan classpath components, including our social security configuration class --> <context:component-scan base-package="org.socialsignin.springsocial.security.config.social" > </context:component-scan> <context:component-scan base-package="org.socialsignin.springsocial.security" > </context:component-scan> <context:component-scan base-package="org.socialsignin.provider" /> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <bean id="hibernate3annotatedsessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="annotatedclasses"> <list> <value>com.cherry.servicedesk.model.customer</value> <value>com.cherry.servicedesk.model.request</value> </list> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <context:annotation-config></context:annotation-config> <bean id="requestserviceimpl" class="com.cherry.servicedesk.rest.requests.service.requestservicesimpl"></bean> <bean id="customerdao" class="com.cherry.servicedesk.dao.impl.customerdaoimpl"> <property name="sessionfactory" ref="hibernate3annotatedsessionfactory" /> </bean> <bean id="requestdao" class="com.cherry.servicedesk.dao.impl.requestdaoimpl"> <property name="sessionfactory" ref="hibernate3annotatedsessionfactory" /> </bean>

requestdaoimpl.java

public class requestdaoimpl implements requestdao{ private sessionfactory sessionfactory; public void setsessionfactory(sessionfactory sessionfactory) { this.sessionfactory = sessionfactory; system.out.print("----------------------------------------auto wired--------------------------------"); } public void inserrequest() { // todo auto-generated method stub } public list<request> listrequest() { // todo auto-generated method stub session session = this.sessionfactory.opensession(); list<request> requestlist = session.createquery("from request").list(); session.close(); homecoming null; } }

spring jersey jax-rs autowired

No comments:

Post a Comment