项目组成
有一个多模块项目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
还未加载
请问该问题该怎么解决,谢谢