【问题标题】:Java module and Cycle exists in module dependencies, ModuleJava模块和Cycle存在于模块依赖中,Module
【发布时间】:2018-03-16 04:29:40
【问题描述】:

我有 2 个项目和

+ proj1 has
    + com.myproj1 has
        + Runner.class
        + Logger.class

+ proj2 has
    + com.myproj2 has
        + Test.class
        + Fact.class

module com.myproj1 {
    requires module com.myproj2;
    exports com.myproj1
}

module com.myproj2 {
    exports com.myproj2;
    requires module com.myproj1;// the problem is "Cycle exists in module 
    dependencies, Module... "
}

我在 com.myproj1 Runner.class 中使用来自 com.myproj2 的 Test.class 直到这里都很好,但是当我尝试使用 Fact.class 中的 Logger.class 它给了我“模块依赖项中存在循环,模块”的问题。我知道模块可以防止循环依赖。但是之后 这种情况有什么解决办法>

【问题讨论】:

    标签: java packages modularity


    【解决方案1】:

    由于您构建模块的方式,这是一个错误的依赖循环。 将Logger 移动到自己的模块中,并将其导入其他两个项目中。这是一般的解决方案:排除人为导致循环的依赖项。

    如果你有一个真正的循环依赖,你需要重新架构整个系统来防止它,但你这里没有那种情况。

    【讨论】:

    • 请您详细说明您的答案。我的意思是我仍然很困惑。当我读到module1 requires module2 and module2 requires module1,怎么不是循环依赖?
    猜你喜欢
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    • 2010-10-22
    • 2020-03-17
    • 2019-02-11
    • 1970-01-01
    相关资源
    最近更新 更多