我正在嘗試使用 JPMS 和 Gradle 多專案功能創建一個多模塊專案。我有 3 個測驗模塊:應用程式、教師和學生。學生依賴于老師,而應用程式依賴于兩者。學生和教師模塊有自己的控制器、服務、物體和存盤庫。每個模塊都有 module-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 抱怨進口。

包'org.springframework.data.jpa.repository'在模塊'spring.data.jpa'中宣告,但模塊'student'沒有讀取它
我不明白如果 Java 有匯入問題,那么為什么我的應用程式運行時沒有錯誤。為什么我的應用程式在沒有 requires 陳述句的情況下運行?
uj5u.com熱心網友回復:
它“似乎”作業的原因是它spring-data-jpa不是模塊化依賴。它可以使用自動模塊名稱包含在模塊化專案中spring.data.jpa。
當您添加requires spring.data.jpa到app模塊時,它在未命名模塊的模塊路徑(及其所有包匯出)上可用。
但是一旦在那里,student當你執行它時實際上可以看到同一個未命名的模塊,所以它“碰巧”作業,但不正確。
您的模塊app和student模塊都依賴于org.springframework.data.jpa.repository包中的類,因此 IntelliJ 建議添加requires spring.data.jpa到student模塊描述符是正確的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/471625.html
標籤:爪哇 弹簧靴 毕业典礼 智能理念 java平台模块系统
