@Autowired does not inject Spring Data JPA Repository - NullPointerException
<p>I'm doing a GWTP project and use Spring Data JPA for a connection with an oracle database. I've read several tutorials in which a repository interface is used directly without the use of implementation. It was @Autowired where needed and it worked fine. I've tried to use the same strategy but it seems the @Autowired annotation is not working at all. </p>

<p>Here is my Repository : </p>

<pre><code>@Repository
public interface BugRepository extends JpaRepository&lt;Bug, Long&gt; {
  List&lt;Bug&gt; findAll();
.....
}
</code></pre>

<p>I try to inject it with @Autowired in my service implementation (I use RESTful services) :</p>

<pre><code>@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/bugs")
@Component
public class BugServiceImpl{
    @Autowired
    private BugRepository bugRepository;

    @GET
    @Path("/findAll")
    public List&lt;Bug&gt; findAll() {
    return bugRepository.findAll();
    }
}
</code></pre>

<p>Here is my Entity :</p>

<pre><code>@Entity
@Table(name = "BUGS")
@SequenceGenerator(name = "BUG_SEQUENCE", sequenceName = "BUG_SEQUENCE")
public class Bug implements Serializable { 

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BUG_SEQUENCE")
   @Column(name="BUG_ID")
   private Long bugId;

   @Column(name="BUG_NAME")
   private String bugName;

   @OneToOne
   @PrimaryKeyJoinColumn
   @Column(name="CREATED_BY")
   private User createdBy;

   @OneToOne
   @PrimaryKeyJoinColumn
   @Column(name="ASSIGNED_TO")
   private User assignedTo;

   @Column(name="CREATION_DATE")
   private Date creationDate;

   @Column(name="LAST_UPDATE_DATE")
   private Date lastUpdateDate;

   @Column(name="BUG_COMMENT")
   private String bugComment;

   @OneToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER, orphanRemoval = true)
   @PrimaryKeyJoinColumn
   @Column(name="PRIORITY_ID")
   private Priority priority;

   @OneToOne
   @PrimaryKeyJoinColumn
   private Status status;

   public Bug() {
   }
}
</code></pre>

<p>I also have applicationContext.xml and persistence.xml in main/resources/META-INF. Here is my applicationContext.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:tx="http://www.springframework.org/schema/tx"
   xmlns:jpa="http://www.springframework.org/schema/data/jpa"
   xmlns:jdbc="http://www.springframework.org/schema/jdbc"
   xmlns:p="http://www.springframework.org/schema/p"

   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/data/jpa
   http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
   http://www.springframework.org/schema/jdbc
   http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"&gt;

&lt;context:component-scan base-package="com.edu" /&gt;

&lt;jpa:repositories base-package="com.edu.server.repositories" /&gt;

&lt;context:annotation-config /&gt;

&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
    &lt;property name="driverClassName" value="oracle.jdbc.OracleDriver" /&gt;
    &lt;property name="url" value="***"/&gt;
    &lt;property name="username" value="***"/&gt;
    &lt;property name="password" value="***"/&gt;
&lt;/bean&gt;

&lt;!-- EntityManagerFactory --&gt;
&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
      p:packagesToScan="com.edu.shared.entity"
      p:dataSource-ref="dataSource"
&gt;
    &lt;property name="jpaVendorAdapter"&gt;
        &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
            &lt;property name="generateDdl" value="true" /&gt;
            &lt;property name="showSql" value="false" /&gt;
        &lt;/bean&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;

&lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
&lt;/bean&gt;
</code></pre>

<p></p>

<p>My persistence.xml :</p>

<pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0"&gt;

&lt;!-- oracle --&gt;

&lt;persistence-unit name="oracle"&gt;
    &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;

    &lt;class&gt;com.edu.server.service.BugServiceImpl&lt;/class&gt;
    &lt;class&gt;com.edu.server.repositories.BugRepository&lt;/class&gt;
    &lt;class&gt;com.edu.shared.entity.Bug&lt;/class&gt;

    &lt;properties&gt;
        &lt;property name="hibernate.archive.autodetection" value="class" /&gt;
        &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /&gt;
        &lt;property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" /&gt;
        &lt;property name="hibernate.connection.url" value="***" /&gt;
        &lt;property name="hibernate.connection.username" value="***" /&gt;
        &lt;property name="hibernate.connection.password" value="***" /&gt;
        &lt;property name="hibernate.flushMode" value="FLUSH_AUTO" /&gt;
        &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;
    &lt;/properties&gt;
&lt;/persistence-unit&gt;
</code></pre>

<p></p>

<p>And finally the exception I get is :</p>

<pre><code>java.lang.NullPointerException
com.edu.server.service.BugServiceImpl.findAll(BugServiceImpl.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
...
</code></pre>

<p>When I debug the code and put a breakpoint to the autowired repository it appears to be null so I suppose it's not injected properly and that's why invoking the method findAll fires the NullPointerException. So, why do you think the @Autowired annotation is not working?</p>