【发布时间】:2019-05-26 15:14:24
【问题描述】:
首先,我不是这方面的专家,这就是我问的原因......
我有两个 Maven 模块,都暴露了几个接口。一个模块处理业务逻辑 (BL),另一个模块是外部系统 (GW) 的网关。 只要网关作为出站网关,循环依赖就没有问题,就是这样:
BL =depends=> GW
网关的接口被@Inject注入到业务逻辑中,一切正常。
模块:业务逻辑:
public class BusinessLogicBean {
@Inject private GatewayInterface interface;
public void sendStuff(Param myParam) {
interface.doSend(myParam);
}
模块:网关
public Interface GatewayInterface {
void doSend(Param someParam);
public class GatewayInterfaceBean {
public void doSend(Param someParam) {
//implementation goes here
一旦我有传入的调用需要委托给我无法指定的业务逻辑:
BL =depends=> GW =depends=> BL
因为 Maven 会抱怨循环依赖。
因此我决定有一个网关的专用接口模块,所以依赖如下:
BL =depends=> I_GW BL
到目前为止一切都很好,尽管@Inject 现在抱怨未解决的依赖项,与上面相同的代码不再工作了。
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type OrderProcess with qualifiers @Default
在注入点 [BackedAnnotatedField] @Inject private de.xyz.abc.externalaccess.control.AccessServiceBean.process 在 de.xyz.abc.externalaccess.control.AccessServiceBean.process(AccessServiceBean.java:0)
模块如下所示: 模块:业务逻辑:
public class BusinessLogicBean {
@Inject private GatewayInterface interface;
模块:Interfaces_Gateway
public Interface GatewayInterface {
void doSend(Param someParam);
模块:网关
public class GatewayInterfaceBean {
public void doSend(Param someParam) {
//implementation goes here
public class ProvisioningServiceTest {
private static SeContainer container;
private static ProvisioningService service;
@Test
public void testPostApplications() {
service.postApplications(null);
}
@BeforeClass
public static void setUp() {
SeContainerInitializer weld = Weld.newInstance();
container = weld.initialize();
service = container.select(ProvisioningService.class).get();
}
@AfterClass
public static void shutDown() {
container.close();
}
}
爆炸发生在@BeforeClass中,我错过了哪一部分? 只要接口和实现在同一个模块中,一切都很好,但只要我把它分成两个模块......
beans.xml(在 META-INF 中的所有三个模块中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<interceptors>
<class>de.abc.util.interceptor.CallTracingInterceptor</class>
<class>de.abc.util.interceptor.PerformanceTracingInterceptor</class>
<class>de.abc.util.interceptor.ValidationInterceptor</class>
</interceptors>
</beans>
焊接 3.1.1
顺便说一句,将这种方法与 WildFly 和 @EJB 注释一起使用根本不会导致问题,但不幸的是,Wildfly 在这里没有选择。
感谢任何提示。
【问题讨论】:
-
所以你可以在不使用 maven 而是手动生成 jar 文件时让它工作?
-
您好,打包不是问题,因为 mvn package 运行良好......它发生在测试期间,当单元测试访问接口包时。
-
那你为什么用maven标记这个问题,甚至在你的标题中使用它?请更正。
-
依赖项的Coz ...也许吧?
-
我想问题是双重的......一个是避免循环依赖,另一个是CDI与模块之间的分布式接口和实现。