我正在使用 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')
}
而 m 在 gradle 文件中使用以下依赖项
org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE
它包括一堆其他依赖项,例如 hibernate n 所有我现在不需要它(只是想使用 spring data jpa),这会导致许多其他问题
那么我怎样才能只使用 spring-data-jpa 及其相关依赖项呢?
尝试禁用类似 excex = { HibernateJpaAutoConfiguration.class} 但效果不佳
提前致谢
我想最简单的解决方案就是包括spring-data-jpa
, not spring-boot-starter-data-jpa
:
compile('org.springframework.data:spring-data-jpa:2.0.0.M2')
或者,如果您真的想离开首发,那么您可以尝试执行以下操作:
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude(module: 'hibernate-core')
exclude(module: 'hibernate-entitymanager')
}
但了解这一点,才能使用spring-data-jpa
你必须有一个持久的提供者,比如hibernate
,只是因为spring-data-jpa
它本身只不过是之上的一个抽象JPA
这反过来又是一个抽象,也是持久提供者之上的一个抽象,例如hibernate
or eclipselink
.
Update
如果您想在 gradle 构建脚本中保留所有 jpa 依赖项,但又不想spring-boot
要使用它们一段时间,然后您必须禁用它们DataSourceAutoConfiguration
and HibernateJpaAutoConfiguration
以及。
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)