当前位置: 首页 > 知识库问答 >
问题:

找不到依赖项类型的合格bean

华星文
2023-03-14

我正在运行一个JUnit测试,嗯,我的Spring启动项目,我是这样写的:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.br.suppcomm.ocp.entity.Login;


public interface LoginDao extends JpaRepository<Login, Long>{
...
}
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.br.suppcomm.ocp.dao.CompanyDAO;
import com.br.suppcomm.ocp.dao.LoginDao;
import com.br.suppcomm.ocp.entity.Login;



@Service
public class LoginService  {

    @Autowired LoginDao loginDao; 


    @Autowired CompanyDAO companyDao;


    public void save(Login login) {

        loginDao.save(login);


    }


    public void delete(Login login) {
         loginDao.delete(login);
    }


    public Login findById(Login login) {
        return loginDao.findOne(login.getLoginId());
    }


    public Login findByEmail(Login login) {
        return loginDao.findByEmail(login.getEmail());
    }


    public Login FindByLogin(Login login) {
        return loginDao.FindByLogin(login);
    }


    public List<Login> getAll() {

        return loginDao.findAll();
    }


    public Login getUserAccessLoginPass(String login, String password) {
        return loginDao.getUserAccessLoginPass(login, password);
    }


    public void update(Login login) {
         loginDao.save(login);

    }
package com.example;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.br.suppcomm.ocp.service.LoginService;


@RunWith(SpringRunner.class)

@SpringBootTest
public class OcpJpaApplicationTests {

    @Autowired LoginService loginService;

    @Test
    public void contextLoads() {


    }    

}
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:        

找到依赖项[com.br.suppcomm.ocp.dao.logindao]得[com.br.suppcomm.ocp.dao.logindao]:需要至少1个具有此依赖项自动候选资格得bean.依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.AutoWired(required=true)};嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖项[com.br.suppcomm.ocp.dao.logindao]类型的合格bean[com.br.suppcomm.ocp.dao.logindao]:至少需要一个合格的bean作为此依赖项的自动候选项。依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.AutoWired(required=true)}

我不知道发生了什么!!求求你了。

共有1个答案

翟新
2023-03-14

添加@Repository您的接口
注释,这样它就可以自动连线了。

@Repository
public interface LoginDao extends JpaRepository<Login, Long>{

}

这样就行了!Exception说SPring不能找到一个限定符,来自动连线需要对其进行sterotype。

 类似资料:
  • 我正在尝试运行批处理,但无法将batchservice注入其中。 BatchApplication.java LeaveAllocationJobConfiguration.java 我该如何解决这个问题?

  • 我有测试Spring Data JPA的示例测试程序,但看起来存储库没有生成。 我的配置: 用户实体:

  • 我通过使用Spring和Hibernate创建实体、服务和服务的JUnit测试开始了我的项目。所有这些都很管用。然后,我添加了spring-mvc来使用许多不同的分步教程来制作这个web应用程序,但是当我试图使用注释制作Controller时,我在部署期间从Glassfish得到错误。我想由于某种原因Spring没有看到我的服务,但经过多次尝试,我仍然无法处理它。 /webapp/web-inf/

  • 我是弹簧靴的初学者。 org.springframework.beans.factory.noSuchBeanDefinitionException:未找到依赖项的[com.foo.dto.UserRepository]类型的合格bean:应至少有一个bean可以作为此依赖项的自动候选项。依赖项注释:{@org.SpringFramework.Beans.Factory.Annotation.Au

  • 当我试图在SpringMVC中使用依赖注入时,我遇到了这个错误。 没有匹配的类型[com.sachin.dao.斯托克道]的bean找到依赖项:预计至少有1 bean有资格作为该依赖项的自动连接候选。依赖注释:{};嵌套异常是org.springframework.beans.factory.NoSuchBean定义异常:没有找到类型[com.sachin.dao.Stock道]的匹配bean的依

  • 我正在使用spring开发一个程序,我面临着这个问题,它说: 根据我的观察,问题出在我的服务/服务实施中 服务: 和我的ServiceImpl 请帮助我解决问题,并提供您的解决方案,thx提前。