AnylineService注入失败

最后更新:2024-01-12 16:50:27 | 状态:未完成

经常是因为没有扫描org.anyline包

如果是springboot项目 需要添加注释
@ComponentScan(basePackages = {"org.anyline","org.anyboot"})
如果用了springboot注意扫描一下org.anyboot(8.7.1及之后版本不需要org.anyboot)

如果是spring-mvc项目 需要添加配置
<context:component-scan base-package="org.anyline"></context:component-scan>


还有可能没有依赖spring-jdbc
如果是spring-mvc项目可以依赖这个
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>

如果是springboot项目可以依赖这个
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

不能在构造函数中使用AnylineService,因为spring上下文环境还没有加载完成AnylineService实例还没有创建

@Component
public class ConsumerSimple {
    @Autowired
    @Qualifier("anyline.service")
    private AnylineService service; 
    public ConsumerSimple(){
		//执行到这里时AnylineService还没有注入
		//在构造函数执行完后才会注入
	}
}

多数据源参考【多数据源场景中AnylineService注入失败

最近更新 搜索 提交