title: @Autowired not working in the RESTFul web service Request
body: <p>I'm using RESTFul webservice with spring hibernate project.I call a webservice with a method but i can't call the @service layer UserService  bean which is null. here my webservice Class.</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  import org.springframework.web.context.support.SpringBeanAutowiringSupport;
  import com.ontag.circa.domain.User;
  import com.ontag.circa.service.UserService;`enter code here`
  
  @Component
  @Path("/users")
  @WebService
  public class UserServiceWS extends SpringBeanAutowiringSupport {
  
      @Autowired
      UserService userService;
  
      User user=new User();
  
      @POST
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      @Produces(MediaType.APPLICATION_JSON)
      @WebMethod
      public String addUserDeatails(MultivaluedMap&lt;String, String&gt; userParams) {
  
              user.setUsername(userParams.getFirst("username"));                  
              user.setGcmid(userParams.getFirst("gcmid"));
              user.setPassword(userParams.getFirst("password"));
  
              userService.addUserDeatails(user);
  
          return "Sucesss !!!!!!!!";
  
      }
  }
  </code></pre>
  
  <p>The @Autowired annotation is not working .please provide the solution</p>
  
  <p>Here my Dependencies</p>
  
  <pre><code>&lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt;
              &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
              &lt;version&gt;1.9.11&lt;/version&gt;
          &lt;/dependency&gt;
  
  
              &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
                  &lt;version&gt;1.8&lt;/version&gt;
              &lt;/dependency&gt;
            &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-core&lt;/artifactId&gt;
                  &lt;version&gt;1.8&lt;/version&gt;
              &lt;/dependency&gt;
  
  
             &lt;dependency&gt;
                  &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-json&lt;/artifactId&gt;
                  &lt;version&gt;1.8&lt;/version&gt;
            &lt;/dependency&gt;
  
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;${log4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;jstl&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ganyo&lt;/groupId&gt;
              &lt;artifactId&gt;gcm-server&lt;/artifactId&gt;
              &lt;version&gt;1.0.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
              &lt;artifactId&gt;derby&lt;/artifactId&gt;
              &lt;version&gt;10.11.1.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
              &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
              &lt;version&gt;10.11.1.1&lt;/version&gt;
          &lt;/dependency&gt;
  
  
              &lt;dependency&gt;
              &lt;groupId&gt;commons-codec&lt;/groupId&gt;
              &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
              &lt;version&gt;1.7&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>Here my web.xml</p>
  
  <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      version="2.5"&gt;
  
      &lt;display-name&gt;Sample Spring Maven Project&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring-config.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;        
      &lt;/servlet-mapping&gt;
  
       &lt;servlet&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt;
          &lt;param-value&gt;com.ontag.circa.rest&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here   spring-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt;
  
  
       &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.ontag.circa.controller" /&gt;
      &lt;context:component-scan base-package="com.ontag.circa.service"&gt;
  &lt;!--    &lt;context:include-filter type="annotation" expression="javax.jws.WebService"/&gt; --&gt;
      &lt;/context:component-scan&gt;
      &lt;context:component-scan base-package="com.ontag.circa.rest"/&gt;
  
      &lt;context:property-placeholder location="classpath:database.properties" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${database.driver}" /&gt;
          &lt;property name="url" value="${database.url}" /&gt;
          &lt;property name="username" value="${database.user}" /&gt;
          &lt;property name="password" value="${database.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;  
              &lt;list&gt;  
                  &lt;value&gt;com.ontag.circa.domain.User&lt;/value&gt;  
                  &lt;value&gt;com.ontag.circa.domain.GCM_Message&lt;/value&gt; 
                  &lt;value&gt;com.ontag.circa.domain.Ad_geo&lt;/value&gt;  
                  &lt;value&gt;com.ontag.circa.domain.Advertisement&lt;/value&gt; 
                  &lt;value&gt;com.ontag.circa.domain.Geofence&lt;/value&gt;  
  
              &lt;/list&gt;  
          &lt;/property&gt; 
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="txManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="persistenceExceptionTranslationPostProcessor"
          class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt;
  
      &lt;bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="messageDaoImpl" class="com.ontag.circa.dao.MessageDaoImpl" /&gt;
      &lt;bean id="userDaoImpl" class="com.ontag.circa.dao.UserDaoImpl" /&gt;
      &lt;bean id="userServiceImpl_1" class="com.ontag.circa.service.UserServiceImpl_1" /&gt;
      &lt;bean id="userServiceImpl" class="com.ontag.circa.rest.UserServiceWS" /&gt;
      &lt;bean id="advertisement" class="com.ontag.circa.service.AdvertisementService" /&gt;
      &lt;bean id="messageService" class="com.ontag.circa.service.MessageService" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>//// this is my Interface </p>
  
  <pre><code>   public interface UserService {
  
          public String addUserDeatails(User user);
          public String getsomevalue(String mess);
  
      }
  
      // this is my implementation class
      import javax.transaction.Transactional;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.Transaction;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Repository;
      import com.ontag.circa.domain.User;
  
      @Repository
      public class UserDaoImpl  implements UserDao  {
  
          @Autowired
          SessionFactory sessionFactory;
  
          @Override
          @Transactional
          public String addUserDeatails(User user)
          {
              Session session=null;
  
                      session = sessionFactory.openSession();
                      Transaction tx = session.beginTransaction();                    
                      session.saveOrUpdate(user);
                      tx.commit();
  
  
  
              return "Succes fully Added the Web service";
          }
  
          public String getsomevalue(String mess)
          {
              System.out.println(mess   +   "   "   + mess);
  
  
              return "message";
          }
      }
  </code></pre>