注入的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默认会扫描同目录及同目录下级目录的类文件。所以&