java - Inner CrudRepository interface in Main doesn't works -


i doing tests spring-data-jpa don't make new file repository interface i've put in main next:

@springbootapplication public class application {  private static final logger log = loggerfactory.getlogger(application.class);  public static void main(string[] args) {     springapplication.run(application.class); }   @bean public commandlinerunner demo(brepository repository) {     return (args) -> {         log.info("insert a");         repository.save(new entitya("testa"));          log.info("find " + repository.findone(1));      }; }   @entity @table(name = "a") public static class entitya{      @id     @generatedvalue(strategy=generationtype.auto)     private integer id;      @column(name = "name")     private string name;      //getters, setters && constructors  }  public interface brepository extends crudrepository<entitya, integer> {  }  } 

then i've tested @bean commandlinerunnerto see output got unsatisfieddependencyexception:

org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'demo' defined in hello.application: unsatisfied dependency expressed through method 'demo' parameter 0: no qualifying bean of type [hello.application$brepository] found dependency [hello.application$brepository]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [hello.application$brepository] found dependency [hello.application$brepository]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}     @ org.springframework.beans.factory.support.constructorresolver.createargumentarray(constructorresolver.java:749) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:467) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1123) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1018) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:510) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:482) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:306) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:302) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:197) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:776) ~[spring-beans-4.3.2.release.jar:4.3.2.release]     @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:861) ~[spring-context-4.3.2.release.jar:4.3.2.release]     @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:541) ~[spring-context-4.3.2.release.jar:4.3.2.release]     @ org.springframework.boot.springapplication.refresh(springapplication.java:759) [spring-boot-1.4.0.release.jar:1.4.0.release]     @ org.springframework.boot.springapplication.refreshcontext(springapplication.java:369) [spring-boot-1.4.0.release.jar:1.4.0.release]     @ org.springframework.boot.springapplication.run(springapplication.java:313) [spring-boot-1.4.0.release.jar:1.4.0.release]     @ org.springframework.boot.springapplication.run(springapplication.java:1185) [spring-boot-1.4.0.release.jar:1.4.0.release]     @ org.springframework.boot.springapplication.run(springapplication.java:1174) [spring-boot-1.4.0.release.jar:1.4.0.release]     @ hello.application.main(application.java:27) [classes/:na]  

finally ensure i've not done wrong i've tested doing interface repository in new file , works.

  • someone knows why doesn't works repository inner interface?

  • is issue or doesn't works reason? (or maybe i'm doing wrong)

spring doesn't see nested repositories, make see, use @enablejparepositories (although it's included in @springbootapplication) , set considernestedrepositories boolean true.

source post: https://stackoverflow.com/a/24485491/2816631


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -