项目组成
有一个多模块项目parent,有A,B,C三个模块
A依赖B,B依赖C
C模块
CamundaApi 类
该类成员注入了
IFlowAuthService
package com.parent.A.core;
@Component
public class CamundaApi {
@Autowired
private IFlowAuthService flowAuthService;
... ...
}
IFlowAuthService 接口
package com.parent.A.service;
public interface IFlowAuthService {
... ...
}
B模块
FlowAuthServiceImpl类
C模块中IFlowAuthService的实现类
package com.parent.B.web.service.impl;
@Service
public class FlowAuthServiceImpl implements IFlowAuthService {
... ...
}
A模块
AApplication
启动类
package com.parent;
@SpringBootApplication
@EnableDiscoveryClient
@EnableDubbo
public class AApplication{
public static void main(String[] args) {
SpringApplication.run(AApplication.class, args);
}
}
启动报错
2021-08-16 11:10:53.789 ERROR 8440 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field flowAuthService in com.parent.C.core.CamundaApi required a bean of type 'com.parent.C.service.IFlowAuthService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.parent.C.service.IFlowAuthService' in your configuration.
描述信息
- 如果只有模块
B和C,B依赖C,启动B可以正常启动 - 在
idea中直接运行A模块启动类不报错,只有package之后java -jar xxx.java时会报上边错误 - 在注入
IFlowAuthService的Autowired中使用required=false依旧报上边错误 - 在
A模块启动类添加@SpringBootApplication(scanBasePackages = {"com.parent"})依旧报上边错误 - 在模块
C的CamundaApi上添加@DependsOn("flowAuthServiceImpl")依旧报上边错误@DependsOn("flowAuthServiceImpl") public class CamundaApi { ... ... }
请问是不是代码加载的顺序造成的该问题?如果是,是不是在加载C的时候B还未加载
请问该问题该怎么解决,谢谢