kir*_*hod 2 spring hibernate gradle spring-data-jpa spring-boot
我正在使用spring boot,以下是我的gradle文件
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE')
compile('org.springframework.boot:spring-boot-starter-web')
compile("com.h2database:h2")
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)
而m在gradle文件中添加以下依赖项
org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE
Run Code Online (Sandbox Code Playgroud)
它包括一堆其他依赖项,如hibernate n我现在不需要它(只是想使用spring数据jpa),这会导致很多其他问题所以我怎么才能只使用spring-data-jpa及其相关依赖?
试图禁用像exclude = {HibernateJpaAutoConfiguration.class},但不顺利
事先提前
我想最简单的解决方案就是包括spring-data-jpa,而不是spring-boot-starter-data-jpa:
compile('org.springframework.data:spring-data-jpa:2.0.0.M2')
Run Code Online (Sandbox Code Playgroud)
或者,如果你真的想要离开,那么你可能会尝试做类似的事情:
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude(module: 'hibernate-core')
exclude(module: 'hibernate-entitymanager')
}
Run Code Online (Sandbox Code Playgroud)
但理解这一点,为了使用spring-data-jpa,你必须有一个持续的供应商一样hibernate,只是因为spring-data-jpa本身只不过是在上面的一个抽象的更多JPA这又是一个抽象以及像持久提供商的顶部hibernate或eclipselink.
更新
如果你想离开的gradle中构建脚本所有JPA的依赖,但不想spring-boot使用它们了一段时间,那么你必须同时禁用DataSourceAutoConfiguration和HibernateJpaAutoConfiguration为好.
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5183 次 |
| 最近记录: |