java - Unable to reference instance of PersonsRepository interface -


i working spring data tutorial here: http://spring.io/guides/tutorials/data/3/

i trying spring 4 + hibernate app , running. have created following unit test according guide:

/**  *   */ package com.corrisoft.air.db.integration;  import static org.junit.assert.*;  import org.junit.test; import org.junit.runner.runwith; import org.springframework.beans.factory.annotation.autowired; import org.springframework.test.context.contextconfiguration; import org.springframework.test.context.junit4.springjunit4classrunner; import org.springframework.test.context.transaction.transactionconfiguration; import org.springframework.transaction.annotation.transactional;  import com.corrisoft.air.db.jpaconfiguration; import com.corrisoft.air.db.repository.personsrepository; import com.corrisoft.air.model.person;      /**      * @author corrisoft android development      *      */     @runwith(springjunit4classrunner.class)     @contextconfiguration(classes = {jpaconfiguration.class})     @transactional     @transactionconfiguration(defaultrollback = true)     public class personsrepositoryintegerationtests {            @autowired           personsrepository personsrepository;            @test           public void thatitemisinsertedintorepoworks() throws exception {             int id = 42;              person person = new person();             person.setid(id);              person.setfirstname("zaphod");             person.setlastname("beeblebrox");              personsrepository.save(person);              person retrievedperson = personsrepository.findbyid(id);              assertnotnull(retrievedperson);             assertequals(id, retrievedperson.getid());           }     }  tests repository i've created here:      /**      *       */     package com.corrisoft.air.db.repository;      import com.corrisoft.air.model.person;     import org.springframework.data.repository.crudrepository;      /**      * @author corrisoft android development      *      */     public interface personsrepository extends crudrepository<person, integer>{         person findbyid(long id);     } 

and i'm getting following exception:

caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.corrisoft.air.db.repository.personsrepository] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)}     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.raisenosuchbeandefinitionexception(defaultlistablebeanfactory.java:1100)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:960)     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:855)     @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:480)     ... 28 more 

the docs proxy object created interface if have jpaconfuration class this:

/**  *   */ package com.corrisoft.air.db;  import java.sql.sqlexception;  import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.sql.datasource;  import org.springframework.context.annotation.bean; import org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.filtertype; import org.springframework.data.jpa.repository.config.enablejparepositories; import org.springframework.jdbc.datasource.embedded.embeddeddatabasebuilder; import org.springframework.jdbc.datasource.embedded.embeddeddatabasetype; import org.springframework.orm.hibernate4.hibernateexceptiontranslator; import org.springframework.orm.jpa.jpatransactionmanager; import org.springframework.orm.jpa.localcontainerentitymanagerfactorybean; import org.springframework.orm.jpa.vendor.hibernatejpavendoradapter; import org.springframework.transaction.platformtransactionmanager; import org.springframework.transaction.annotation.enabletransactionmanagement;  import com.corrisoft.air.db.repository.personsrepository;  /**  * @author corrisoft android development  *   */ @configuration @enablejparepositories(basepackages = "com.corrisoft.db.repository",                        includefilters = @componentscan.filter(value = { personsrepository.class }, type = filtertype.assignable_type)) @enabletransactionmanagement public class jpaconfiguration {      @bean     public datasource datasource() throws sqlexception {         embeddeddatabasebuilder builder = new embeddeddatabasebuilder();         return builder.settype(embeddeddatabasetype.h2).build();     }      @bean     public entitymanagerfactory entitymanagerfactory() throws sqlexception {          hibernatejpavendoradapter vendoradapter = new hibernatejpavendoradapter();         vendoradapter.setgenerateddl(true);          localcontainerentitymanagerfactorybean factory = new localcontainerentitymanagerfactorybean();         factory.setjpavendoradapter(vendoradapter);         factory.setpackagestoscan("com.corrisoft.air.model");         factory.setdatasource(datasource());         factory.afterpropertiesset();          return factory.getobject();     }      @bean     public entitymanager entitymanager(entitymanagerfactory entitymanagerfactory) {         return entitymanagerfactory.createentitymanager();     }      @bean     public platformtransactionmanager transactionmanager() throws sqlexception {         jpatransactionmanager txmanager = new jpatransactionmanager();         txmanager.setentitymanagerfactory(entitymanagerfactory());         return txmanager;     }      @bean     public hibernateexceptiontranslator hibernateexceptiontranslator() {         return new hibernateexceptiontranslator();     } } 

i've found several issues tutorial , thinking another.

you scanning wrong package repositories:

... basepackages = "com.corrisoft.db.repository" ... 

whereas correct 1

import com.corrisoft.air.db.repository.personsrepository; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -