Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了java – Spring @Autowired无法连接Jpa存储库大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在这里明显遗漏了什么.
我正在制作一个简单的弹簧启动应用程序,其中包含弹簧数据jpa并面临以下错误

Caused by: org.springframework.beans.factory.NoSuchBeanDeFinitionException: No qualifying bean of type [loCassa.domain.repository.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency Annotations: {@org.springframework.beans.factory.Annotation.Autowired(required=truE)}
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.raiseNoSuchBeanDeFinitionException(DefaultListablebeanfactory.java:1373) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.doResolveDependency(DefaultListablebeanfactory.java:1119) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.resolveDependency(DefaultListablebeanfactory.java:1014) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.Annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 32 common frames omitted

我的代码

应用:

@SpringBootApplication
@ComponentScan(basePackages = {"app.controller","app.domain"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

}

的pom.xml

<><><><><><><><><><><><><><><><><><><>

控制器:

@RestController
public class TESTController {

    @Autowired
    Personservice personservice;

    @requestMapping("/")
    public String index() {
        return "Test spring boot";
    }

    @requestMapping("/person/{iD}")
    public Person personById(@PathVariable Long id) {
        return personservice.findPerson(id);
    }
}

Personservice:

public interface Personservice {

    Person findPerson(Long id);
}

PersonserviceImpl:

@service
public class PersonserviceImpl implements Personservice {

    @Autowired
    PersonRepository personRepository;

    public Person findPerson(Long id) {
       return personRepository.findOne(id);
    }
}

PersonRepository(这个不能@R_403_1913@):

public interface PersonRepository extends CrudRepository

已在网上搜索过.我没找到一件事.有任何想法吗?

@H_301_62@最佳答案

大佬总结

以上是大佬教程为你收集整理的java – Spring @Autowired无法连接Jpa存储库全部内容,希望文章能够帮你解决java – Spring @Autowired无法连接Jpa存储库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。