Spring - No qualifying bean of type -
just started learning spring. trying learn jpa creating person class, personrepository
, persondao
, main
. i've looked on stackoverflow answers think did right... exception:
exception in thread "main" org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'beans.persondao' available @ org.springframework.beans.factory.support.defaultlistablebeanfactory.getbean(defaultlistablebeanfactory.java:353) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.getbean(defaultlistablebeanfactory.java:340) @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1090) @ com.example.srpingdatajpa.main.main(main.java:15)
this classes:
person.class:
package beans; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.table; @entity @table(name="workers") public class person { @id @column(name="name") private string name; public person(string name) { this.name = name; } public string getname() { return name; } public void setname(string name) { this.name = name; } @override public string tostring() { return "person [name=" + name + "]"; } }
personrepo.class:
package beans; import java.util.list; import org.springframework.data.repository.crudrepository; import org.springframework.stereotype.repository; @repository public interface personrepo extends crudrepository<person, string>{ list<person> findbyname(string name); }
persondao.class:
package beans; import java.util.list; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.repository; @repository public class persondao { @autowired private personrepo personrepo; public persondao() { } public void createperson(person person){ personrepo.save(person); } public list<person> find(string name){ return personrepo.findbyname(name); } }
main.class:
package com.example.srpingdatajpa; import javax.transaction.transactional; import org.jboss.jandex.main; import org.springframework.boot.springapplication; import org.springframework.context.applicationcontext; import beans.persondao; @transactional public class main { public static void main(string[] args) { applicationcontext context = springapplication.run(main.class, args); persondao persondao = context.getbean(persondao.class); system.out.println(persondao .find("daniel")); } }
any guys?
put @springbootapplication annotation in main class, work.
wiki
Comments
Post a Comment