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

NoSuchBeanDefinitionException:没有限定类型的bean

禄豪
2023-03-14

我在调用get请求(modes-calcul)时遇到这个错误,我不明白为什么...我的依赖注入是正确的吗?

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.margaux.margaux.repository.ModeCalculDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

ModeCalculController:

@Slf4j
@Transactional
@RestController
@RequestMapping("modes-calcul")
public class ModeCalculController {
    private ModeCalculService modeCalculService;

    @Autowired
    public ModeCalculController(ModeCalculService modeCalculService) {
        this.modeCalculService = modeCalculService;
    }

    @GetMapping()
    public ResponseEntity<List<ModeCalculDTO>> getModesCalcul() {
        return new ResponseEntity<List<ModeCalculDTO>>(modeCalculService.getModesCalcul(), HttpStatus.OK);
    }
}
@Slf4j
@Service
@Transactional
public class ModeCalculServiceImpl implements ModeCalculService {
    private ModeCalculDAO modeCalculDAO;

    @Autowired
    @Lazy
    public ModeCalculImpl(ModeCalculDAO modeCalculDAO){
        this.modeCalculDAO = modeCalculDAO;
    }

    @Override
    public List<ModeCalculDTO> getModesCalcul() {
        ModelMapper mapper = new ModelMapper();
        List<ModeCalcul> modesCalcul = modeCalculDAO.findAll();

        return modesCalcul
                .stream()
                .map(modeCalcul -> mapper.map(modeCalcul, ModeCalculDTO.class))
                .collect(Collectors.toList());
    }
}
@Repository
public interface ModeCalculDAO extends JpaRepository<ModeCalcul, Long> {
}

谢谢你的帮助..

共有1个答案

颜实
2023-03-14

检查ModeCalculDAO是否在主程序的子包中,如果不是子包,则尝试在主程序中添加@ComponentScan(包名)

 类似资料: