Spring boot with spring data repository - cannot autowire own repository -
i'm trying create new project spring boot use spring data (spring repositories...), i'm getting error
org.springframework.beans.factory.beancreationexception: error creating bean name 'hqltester': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: com.service.companyrepository com.example.hqltester.companyrepository; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.service.companyrepository] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)} @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:334) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1214) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:543) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:772) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:839) ~[spring-context-4.2.6.release.jar:4.2.6.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:538) ~[spring-context-4.2.6.release.jar:4.2.6.release] @ org.springframework.boot.springapplication.refresh(springapplication.java:766) [spring-boot-1.3.5.release.jar:1.3.5.release] @ org.springframework.boot.springapplication.createandrefreshcontext(springapplication.java:361) [spring-boot-1.3.5.release.jar:1.3.5.release] @ org.springframework.boot.springapplication.run(springapplication.java:307) [spring-boot-1.3.5.release.jar:1.3.5.release] @ org.springframework.boot.springapplication.run(springapplication.java:1191) [spring-boot-1.3.5.release.jar:1.3.5.release] @ org.springframework.boot.springapplication.run(springapplication.java:1180) [spring-boot-1.3.5.release.jar:1.3.5.release] @ com.example.hqltesterapplication.main(hqltesterapplication.java:18) [classes/:na] caused by: org.springframework.beans.factory.beancreationexception: not autowire field: com.service.companyrepository com.example.hqltester.companyrepository; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.service.companyrepository] found dependency: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {@org.springframework.beans.factory.annotation.autowired(required=true)} @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:573) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.annotation.injectionmetadata.inject(injectionmetadata.java:88) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor.postprocesspropertyvalues(autowiredannotationbeanpostprocessor.java:331) ~[spring-beans-4.2.6.release.jar:4.2.6.release] ... 16 common frames omitted caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [com.service.companyrepository] 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:1373) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.doresolvedependency(defaultlistablebeanfactory.java:1119) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.support.defaultlistablebeanfactory.resolvedependency(defaultlistablebeanfactory.java:1014) ~[spring-beans-4.2.6.release.jar:4.2.6.release] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:545) ~[spring-beans-4.2.6.release.jar:4.2.6.release] ... 18 common frames omitted
here project structure
hqltesterapplication.java
@springbootapplication @componentscan("com.*") @configuration @enablejparepositories("com.service.*") public class hqltesterapplication { public static void main(string[] args) { springapplication.run(hqltesterapplication.class, args); } }
hqltester.java
@service public class hqltester { @autowired companyrepository companyrepository; @postconstruct void testhql(){ system.out.println("test"); list<company> companies = companyrepository.findcompanywithemployes2(new date(), 1l); list<company> companies2 = companyrepository.findcompanywithemployes(new date(), 1l); } }
companyrepository.java
public interface companyrepository extends jparepository<company, long> { @query(" select c company c ,employee e left join fetch c.employees emp e.id=emp.id , e.hiredate > :dateee , e.departuredate < :dateee , c.id=:id") list<company> findcompanywithemployes2(@param("dateee") date dateee, @param("id") long id); @query(" select c employee e left join fetch e.company c e.hiredate > :dateee , e.departuredate < :dateee , c.id=:id") list<company> findcompanywithemployes(@param("dateee") date dateee, @param("id") long id); }
company.java
@entity public class company { @id long id; string name; @onetomany(mappedby = "company", cascade = cascadetype.refresh, fetch = fetchtype.lazy) private set<employee> employees; }
employee.java
@entity public class employee { @id long id; string name; date hiredate; date departuredate; @manytoone @joincolumn(name = "companyid", insertable = false, updatable = false) company company; }
application.properties
spring.datasource.url:jdbc:oracle:thin:@//myserver.com:1521/testdb spring.datasource.username=testuser spring.datasource.password=testuser spring.datasource.driver-class-name=oracle.jdbc.oracledriver spring.jpa.hibernate.ddl-auto=none spring.jpa.database-platform=org.hibernate.dialect.oracle10gdialect spring.jpa.show-sql = true logging.level.org.springframework.data=debug
could please tell me missed configure repository not taken in context?
i had change annotation on hqltesterapplication.java
@springbootapplication @componentscan("com") @enablejparepositories("com.service") @entityscan("com.model") public class hqltesterapplication { public static void main(string[] args) { springapplication.run(hqltesterapplication.class, args); } }
Comments
Post a Comment