title: SPRING - @Autowired and @Service does not work
body: <p>I know that exists a lot of questions of that, i read a lot and no one can help me. Thanks for helping me.</p>
  
  <p>I dont like the spring way to define every bean in xml so i used a scanner in my apllication context but i think that only sacan the @Component (my managed beans) but it dont wanna catch the @Service and @Repository, i said that cuz my Service is null.</p>
  
  <p>Thats the spring stuff in web.xml</p>
  
  <pre><code>&lt;!-- Archivo de configuraciones de Spring y JSF --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath*:WEB-INF/context/applicationContext*.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Línea especial para la integración con un Java-based web framework (JSF) --&gt;    
      &lt;listener&gt;
          &lt;listener-lass&gt;org.springframework.web.context.ContextLoaderListener    
  </code></pre>
  
  <p>
          </p>
  
  <p>Thats my application-context.xml</p>
  
  <pre><code> &lt;context:spring-configured/&gt;     
  
      &lt;!-- Escanear todos los componentes y beans en vez de instanciar 1 por 1 --&gt;
      &lt;context:component-scan base-package="paquete" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
  
       &lt;!-- Identificar todos los beans por las anotaciones --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;!-- Archivo de propiedades configurables (database, messages, etc) --&gt;
      &lt;context:property-placeholder  location="classpath*:META-INF/*.properties"/&gt;
  
  
      &lt;!-- Gestor de transacciones de SPRING --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;bean class="org.springframework.orm.jpa.JpaTransactionManager"     id="transactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- El conversador entre nuestras entidades y las tablas de BD --&gt;
      &lt;bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="persistenceUnit" /&gt;
          &lt;property name="persistenceXmlLocation" value="classpath:/WEB-INF/persistence.xml" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="loadTimeWeaver"&gt;
              &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /&gt;
          &lt;/property&gt;
          &lt;property name="jpaVendorAdapter" ref="vendorAdapter" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Integración de Spring e Hibernate, no es obligatorio --&gt;
      &lt;bean id="vendorAdapter"
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;property name="databasePlatform" value="${hibernate.dialect}" /&gt;
          &lt;property name="showSql" value="${hibernate.show_sql}" /&gt;
          &lt;property name="generateDdl" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Formalidad de dataSource de SPRING --&gt;
      &lt;bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"&gt;
          &lt;property name="driverClassName" value="${database.driverClassName}"/&gt;
          &lt;property name="url" value="${database.url}"/&gt;
          &lt;property name="username" value="${database.username}"/&gt;
          &lt;property name="password" value="${database.password}"/&gt;
          &lt;property name="testOnBorrow" value="true"/&gt;
          &lt;property name="testOnReturn" value="true"/&gt;
          &lt;property name="testWhileIdle" value="true"/&gt;
          &lt;property name="timeBetweenEvictionRunsMillis" value="1800000"/&gt;
          &lt;property name="numTestsPerEvictionRun" value="3"/&gt;
          &lt;property name="minEvictableIdleTimeMillis" value="1800000"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>In my package "paquete" (package in spanish, im from Peru sorry for my bad english) i have 3 subpackages, so in netbeans i see 3 packages like "paquete.beans", "paquete.service" and "paquete.repositorios". im called with the component scanner in the "paquete" package</p>
  
  <p>Im using primefaces so y hace a helloJSFBean that is..</p>
  
  <pre><code> @ManagedBean
      @Scope("session")
      @Component
      public class helloPageJSFBean {
  
          private String nombre;
          private String nombre2;
  
          public String getNombre2() {
              return nombre2;
          }
  
          public void setNombre2(String nombre2) {
              this.nombre2 = nombre2;
          }
  
          @Autowired
          HelloService helloService;
  
          @PostConstruct
          public void init(){
              nombre="hi";
          }
  
          public void saludar(ActionEvent actionEvent){
              nombre2=helloService.saludar(nombre);
          }
  
  
          /* 
           *Getters and Setters
           */
          public String getNombre() {
              return nombre;
          }
  
          public void setNombre(String nombre) {
              this.nombre = nombre;
          }
  
      }
  </code></pre>
  
  <p>so i call my helloService and is...</p>
  
  <pre><code>  @Service
  public class HelloServiceImpl implements HelloService{
  
      @Autowired
      protected HelloRepository helloRepository;
  
      @Override
      public String saludar(String nombre) {
          return helloRepository.saludar(nombre);
      }
  
  }
  </code></pre>
  
  <p>and my repository is</p>
  
  <pre><code>  @Repository
      public class HelloRepositoryImpl implements HelloRepository {
  
          @Override
          public String saludar(String nombre) {
              return "Hola "+nombre+", estás haciendo un excelente trabajo";
          }
  
      }
  </code></pre>
  
  <hr>
  
  <p>The problem is that i get the <code>NullPointerException</code> in my "saludar" method, in the debug my service is null and is not a instance of helloServiceImpl, so i guess the @Autowired its not workin.</p>
  
  <p>All help that i recive it will be great, i have losted 2 weeks and nothing. Thank all. </p>