autowired注入jar中的依赖_注入jar包里的对象,用@autowired的实例

注入的jar包如果不能直接使用 @autowired 来使用,可以采用如下方法:

@Configuration

public class DemoConfiguration {

@Bean

public Demo demo() {

return new Demo(); //该对象为Jar包对象

}

}

补充知识:引入第三方包 @Autowired Spring注入失败解决方案

一、问题背景

开发工程中,我负责的微服务需要依赖中台服务层,在调用该服务的功能接口时,@Autowired 注入方式启动报错:

Description:

Field clientRouter in com.baiwang.cloud.spush.client.SPushClient required a bean of type 'com.baiwang.cloud.spush.client.router.IClientRouter' that could not be found.

Action:

Consider defining a bean of type 'com.baiwang.cloud.spush.client.router.IClientRouter' in your configuration.

二、问题解决

1、@ComponentScan用来指定扫描的组建所在的包路径或class文件。在不指定参数的时候,SpringBoot的@ComponentScan默认会扫描同目录及同目录下级目录的类文件。所以&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值