应用程序成功构建,但Intellij表示我的模块没有读取其他一些模块

发布于 2025-01-27 07:28:28 字数 1967 浏览 2 评论 0原文

我正在尝试使用JPM和Gradle多项目功能来创建一个多模块项目。我有3个用于测试的模块:应用程序,老师和学生。学生取决于老师,并且应用程序都取决于两者。学生和教师模块有自己的控制器,服务,实体和存储库。每个模块都有模块info.java文件。

module app {
    requires java.sql;
    requires org.hibernate.orm.core;

    requires spring.boot;
    requires spring.data.jpa;
    requires spring.boot.autoconfigure;

    requires spring.core;
    requires spring.beans;
    requires spring.context;

    requires teacher;
    requires student;

    opens az.chaypay.app to spring.core;
    exports az.chaypay.app to spring.beans, spring.context;
}

module teacher {
    requires static lombok;

    requires spring.web;

    exports az.chaypay.teacher to app;
    exports az.chaypay.teacher.api to student;
    exports az.chaypay.teacher.controller to spring.beans;
    exports az.chaypay.teacher.service.impl to spring.beans;

    opens az.chaypay.teacher.controller to spring.core;
    opens az.chaypay.teacher.repository.dao to spring.core, com.fasterxml.jackson.databind, org.hibernate.orm.core;
}

module student {
    requires static lombok;
    requires com.fasterxml.jackson.databind;

    requires spring.web;

    exports az.chaypay.student to app;
    exports az.chaypay.student.controller to spring.beans;
    exports az.chaypay.student.service.impl to spring.beans;

    opens az.chaypay.student.controller to spring.core;
    opens az.chaypay.student.repository.dao to spring.core, com.fasterxml.jackson.databind, org.hibernate.orm.core;

    requires teacher;
}

当我使用这些设置运行应用程序时,一切都起作用。应用程序已成功构建和运行。但是Intellij抱怨进口。

package'org.springframework.data.jpa.repository'在module'spring.data.jpa中声明,但是模块'student'''''''''Student'''''''''''Student'''

我不明白,如果java对导入有问题,那么我为什么会读应用程序运行没有错误。为什么我的应用程序不需要需要语句?

I am trying to create a multi-module project by using JPMS and Gradle multi-project functionalities. I have 3 modules for the testing: app, teacher and student. The student depends on the teacher and the app depends on both. Student and teacher modules have their own controller, service, entity, and repository. Each module has module-info.java file.

module app {
    requires java.sql;
    requires org.hibernate.orm.core;

    requires spring.boot;
    requires spring.data.jpa;
    requires spring.boot.autoconfigure;

    requires spring.core;
    requires spring.beans;
    requires spring.context;

    requires teacher;
    requires student;

    opens az.chaypay.app to spring.core;
    exports az.chaypay.app to spring.beans, spring.context;
}

module teacher {
    requires static lombok;

    requires spring.web;

    exports az.chaypay.teacher to app;
    exports az.chaypay.teacher.api to student;
    exports az.chaypay.teacher.controller to spring.beans;
    exports az.chaypay.teacher.service.impl to spring.beans;

    opens az.chaypay.teacher.controller to spring.core;
    opens az.chaypay.teacher.repository.dao to spring.core, com.fasterxml.jackson.databind, org.hibernate.orm.core;
}

module student {
    requires static lombok;
    requires com.fasterxml.jackson.databind;

    requires spring.web;

    exports az.chaypay.student to app;
    exports az.chaypay.student.controller to spring.beans;
    exports az.chaypay.student.service.impl to spring.beans;

    opens az.chaypay.student.controller to spring.core;
    opens az.chaypay.student.repository.dao to spring.core, com.fasterxml.jackson.databind, org.hibernate.orm.core;

    requires teacher;
}

When I run my application with these settings everything works. Applications are successfully built and run. But IntelliJ complains about imports.

enter image description here

Package 'org.springframework.data.jpa.repository' is declared in module 'spring.data.jpa', but module 'student' does not read it

I don't understand that if Java has a problem with imports then why does my application run without errors. Why does my application run without requires statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2025-02-03 07:28:28

它“似乎”起作用的原因是spring-data-jpa不是模块化的依赖性。它可以使用自动模块名称spring.data.jpa将其包含在模块化项目中。

当您将添加需要Spring.data.jpaapp模块时,它可在未命名的模块中在ModulePath(带有所有软件包)上可用。

但是,一旦到达,student在执行它时实际上可以看到相同的未命名模块,因此它可以“碰巧”工作,但不正确。

您的appstudent模块都取决于org.springframework.data.data.jpa.repository package的类中的类,因此Intellijij建议是添加<<<代码>需要spring.data.jpa student模块描述符正确。

The reason that it "seems" to work is that spring-data-jpa is not a modular dependency. It can be included in a modular project using the automatic module name spring.data.jpa.

When you add the requires spring.data.jpa to the app module, it is available on the modulepath (with all its packages exported) in the unnamed module.

But once there, student can actually see that same unnamed module when you execute it, so it "happens" to work, but is incorrect.

Both your app and student modules depend on classes in the org.springframework.data.jpa.repository package, so the IntelliJ suggestion to add requires spring.data.jpa to the student module descriptor is correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文