admin管理员组文章数量:1431813
文章目录
- 一、问题描述
- 二、解决方法
一、问题描述
运行 SpringBoot 启动类,报错:
可以看到,它是说 WeiXinPayController 中,用到了 OrderService ,但是呢,Spring 扫描不到。
二、解决方法
其实可以看出来, WeiXinPay 和 Order 分属两个工程,具有各自的功能,在一个工程里调用另一个工程的 service 层,其实是不妥的,如果业务有交叉,可以用 feign 的方式调用 controller 层。
事已至此,先解决一下这个错误吧。
看看 SpringBootApplication 源码:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
excludeFilters = {@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
可以看到,@ComponentScan ,只能扫描与控制器在同一个包下以及其子包下的 @Component 注解,以及能将指定注解的类自动注册为 Bean 的@Service 、@Controller 和 @ Repository,所以, WeiXinPayController 想识别到 OrderService,需要在 pay 的启动类上使用注解 :
@ComponentScan(basePackages = {"com.changgou.order.service"})
本文标签: 错误definingBeanConfigurationxxxrService
版权声明:本文标题:解决错误:Consider defining a bean of type ‘xxxrService‘ in your configuration 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1738335643a2076863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论