应用程序成功构建,但Intellij表示我的模块没有读取其他一些模块
我正在尝试使用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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它“似乎”起作用的原因是
spring-data-jpa
不是模块化的依赖性。它可以使用自动模块名称spring.data.jpa
将其包含在模块化项目中。当您将
添加需要Spring.data.jpa
到app
模块时,它可在未命名的模块中在ModulePath(带有所有软件包)上可用。但是,一旦到达,
student
在执行它时实际上可以看到相同的未命名模块,因此它可以“碰巧”工作,但不正确。您的
app
和student
模块都取决于org.springframework.data.data.jpa.repository
package的类中的类,因此Intellijij建议是添加<<<代码>需要spring.data.jpastudent
模块描述符正确。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 namespring.data.jpa
.When you add the
requires spring.data.jpa
to theapp
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
andstudent
modules depend on classes in theorg.springframework.data.jpa.repository
package, so the IntelliJ suggestion to addrequires spring.data.jpa
to thestudent
module descriptor is correct.