简体   繁体   English

Quarkus 多模块循环引用问题

[英]Quarkus multi-module cyclic reference problem

This is my first project using Quarkus.这是我第一个使用 Quarkus 的项目。
I made a multi-module project and in the parent pom I have this module structure:我做了一个多模块项目,在父 pom 中我有这个模块结构:

    <modules>
        <module>domain</module>
        <module>application</module>
        <module>client</module>
    </modules>

In my domain module I have my interfaces that are supposed to be implemented by the application and client modules.在我的domain模块中,我的接口应该由applicationclient模块实现。 So I added the <dependency> in the application and the client modules, for implementing the domain interfaces.所以我在applicationclient模块中添加了<dependency> ,用于实现domain接口。
But when I want to add the <dependency> of the application module in my domain it doesn't work and when I build I have this error:但是,当我想在我的domain添加application模块的<dependency>时,它不起作用,并且在构建时出现此错误:

[ERROR] [ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.test.name:application:0.0.1-SNAPSHOT'}' and 'Vertex{label='com.test.name:domain:0.0.1-SNAPSHOT'}' introduces to cycle in the graph com.test.name:domain:0.0.1-SNAPSHOT --> com.test.name:application:0.0.1-SNAPSHOT --> com.test.name:domain:0.0.1-SNAPSHOT @ [ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.test.name:application:0.0.1-SNAPSHOT'}' and 'Vertex{label='com.test.name:domain:0.0.1-SNAPSHOT'}' introduces to cycle in the graph com.test.name:domain:0.0.1-SNAPSHOT --> com.test.name:application:0.0.1-SNAPSHOT --> com.test.name:domain:0.0.1-SNAPSHOT -> [Help 1] [错误] [错误]反应器中的项目包含循环引用:'Vertex{label='com.test.name:application:0.0.1-SNAPSHOT'}'和'Vertex{label='com.test之间的边缘.name:domain:0.0.1-SNAPSHOT'}' 在图中引入循环 com.test.name:domain:0.0.1-SNAPSHOT --> com.test.name:application:0.0.1-SNAPSHOT -- > com.test.name:domain:0.0.1-SNAPSHOT @ [错误] 反应器中的项目包含循环引用:'Vertex{label='com.test.name:application:0.0.1-SNAPSHOT'之间的边缘}' 和 'Vertex{label='com.test.name:domain:0.0.1-SNAPSHOT'}' 在图中引入循环 com.test.name:domain:0.0.1-SNAPSHOT --> com.test .name:application:0.0.1-SNAPSHOT --> com.test.name:domain:0.0.1-SNAPSHOT -> [帮助 1]

I need this for dependency injection, my CDI container need to find the implementation to inject it.我需要这个来进行依赖注入,我的 CDI 容器需要找到注入它的实现。 Does anyone have a solution?有没有人有办法解决吗?

The way I like to structure my projects is roughly as follows:我喜欢构建项目的方式大致如下:

  • Modules containing interfaces that are dependencies to other modules, similar to your domain module.包含依赖于其他模块的接口的模块,类似于您的domain模块。 They can be as fine or coarse grained as your design dictates.它们可以根据您的设计要求细粒度或粗粒度。 Examples are app-service-interfaces (eg interfaces for the business logic), app-dao-interfaces (interfaces for the DAO layer) etc.示例是app-service-interfaces (例如业务逻辑的接口)、 app-dao-interfaces (DAO 层的接口)等。
  • Modules containing the implementation of a single "interface" module.包含单个“接口”模块实现的模块。 The implementation modules depend only on interface modules, obviously the one they implement and any other they need.实现模块仅依赖于接口模块,显然是它们实现的模块以及它们需要的任何其他模块。 Eg the module app-service-impl depends and implement the app-service-interfaces module, but also depends on the app-dao-interfaces module because it needs access to the application's datastore facilities.例如,模块app-service-impl依赖并实现app-service-interfaces模块,但也依赖于app-dao-interfaces模块,因为它需要访问应用程序的数据存储设施。 The implementation of app-dao-interfaces could be app-dao-jpa , if I choose to use JPA for the DAO layer.如果我选择使用 JPA 作为 DAO 层, app-dao-interfaces的实现可以是app-dao-jpa (Sidenote: keeping the interface modules free of dependencies to the actual technology used to implement them allows you to switch implementations easily.) (旁注:保持接口模块不依赖于用于实现它们的实际技术,这样您就可以轻松地切换实现。)
    • Neither the interface nor the implementation modules depend on the specific environment I intend to deploy on;接口和实现模块都不依赖于我打算部署的特定环境; Quarkus, JEE, Spring, Play, whatever. Quarkus、JEE、Spring、Play 等等。
  • Finally, a single module, I call it the "assembly" module (term borrowed from our.Net colleagues) that depends on all the implementation modules I intend to deploy plus the specific environment (eg Quarkus for this case).最后,一个单独的模块,我称它为“组装”模块(从我们的.Net 同事借来的术语),它依赖于我打算部署的所有实现模块以及特定环境(例如本例中的 Quarkus)。 This module may contain environment-specific implementations of some components (eg Microprofile Config implementation for the component that reads and holds the configuration in a Quarkus environment).该模块可能包含某些组件的特定于环境的实现(例如,在 Quarkus 环境中读取和保存配置的组件的 Microprofile Config 实现)。

2 final comments: 2条最终评论:

  • This is a proposal for one possible solution that works for me.这是一个对我有用的可能解决方案的建议。 I am sure there are plenty of others that work just as well;我相信还有很多其他的也一样。 or this may not work for you for any reason!或者这可能对你不起作用!
  • I have applied this principle in this pet project and have a relevant explanation in this earlier, abandoned incarnation of the same project.我在这个宠物项目中应用了这个原则,并且在这个早期的同一个项目的废弃化身中有相关的解释。 Beware, these are just scratch projects:)当心,这些只是临时项目:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM