spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration的问题

编程知识 更新时间:2023-05-02 05:34:58

在搭建一个简单的关于springboot的AOP编程时,遇到一个Consider defining a bean of type ‘com.springboot.chapter04.service.impl.UserServiceImpl’ in your configuration的问题。

Description:

Field helloService in com.example.demo.service.TestController required a bean of type 'com.springboot.chapter04.service.impl.UserServiceImpl' that could not be found.


Action:

Consider defining a bean of type 'com.springboot.chapter04.service.impl.UserServiceImpl' in your configuration.

最后找到问题,就是springboot启动类包扫描的路径和我接口实现类的路径不是在同一个目录中
解决办法是将启动类包扫描的路径改成与实现类相同的路径
实现类的路径是

package com.springboot.chapter04.service.impl;
@SpringBootApplication(scanBasePackages = "com.springboot.chapter04")

这样做的一个缺点是将一些不需要注入的类也一起注入了
另一个方法是将实现类移到启动类的同一个路径下或者子路径下

更多推荐

spring boot自动注入出现Consider defining a bean of type 'xxx' in your config

本文发布于:2023-04-26 07:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/38ffd38ed9d37606047cfb46dac43173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:defining   boot   spring   bean   configuration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104694文章数
  • 26219阅读数
  • 0评论数