我有以下问题。在我的 ORMConfiguration 文件中,我正在设置实现 JPA 所需的一些基本属性。在这个 ORMConfig.java 文件中,我还有一个主类。 类导入看起来像这样
package io.good.asset.ams.dao.configuration;
import io.good.asset.ams.model.domain.Category;
import io.good.asset.ams.model.domain.Company;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import java.util.Map;
项目是使用gradle构建的,依赖设置如下:
project(':AMSRepository'){
dependencies {
compile project(':AMSModel')
compile("org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}")
compile("org.hibernate:hibernate-core:5.2.10.Final")
compile("com.h2database:h2:${h2Ver}")
testCompile("org.liquibase:liquibase-core:${liquibaseSpringVer}")
}
}
因为这是一个多模块项目,我类中的前两个导入指向不同的模块,当我尝试从根目录或单个 AMSRepository 模块构建完整项目时,出现错误
error: package io.good.asset.ams.model.domain does not exist import io.good.asset.ams.model.domain.Category; ^ error: package io.good.asset.ams.model.domain does not exist import io.good.asset.ams.model.domain.Company;
我的 settings.gradle 看起来像这样
rootProject.name = 'AMS'
include 'AMSRepository'
include 'AMSService'
include 'AMSWeb'
include 'AMSModel'
我还使用了 IntelliJ 模块设置面板,并尝试手动向这个模块麻烦的模块添加 decencies,最奇怪的是,当我在 ORMConfig.java 中运行主类并实例化对象时,没有任何下划线是错误的从这些模块中,一切正常。
最佳答案
Like a war file, a Spring Boot application is not intended to be used as a dependency. If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.
关于java - 找不到包,Gradle 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44473603/