如何从弹簧引导中排除依赖关系 [英] how to exclude dependencies from spring boot
问题描述
我使用spring引导,以下是我的gradle文件
buildscript {
ext {
springBootVersion ='2.0.0.BUILD-SNAPSHOT'
}
知识库{
mavenCentral()
maven {urlhttps://repo.spring.io/snapshot}
maven {urlhttps://repo.spring.io/milestone}
}
依赖关系{
classpath(org.springframework.boot:spring-boot-gradle -plugin:$ {springBootVersion})
}
}
apply plugin:'java'
apply plugin:'eclipse-wtp'
apply插件:'org.springframework.boot'
apply插件:'io.spring.dependency-management'
apply插件:'war'
version ='0.0.1- SNAPSHOT'
sourceCompatibility = 1.8
存储库{
mavenCentral()
maven {urlhttps://repo.spring.io/snapshot}
maven {urlhttps://repo.spring.io/milestone}
}
配置{
providesRuntime
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')
}
while m在gradle文件中添加以下依赖项:
org.springframework.boot: spring-boot-starter-data-jpa:1.2.1.RELEASE
其中包括其他一些依赖关系像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')
或者,如果您真的想离开启动器,可能会尝试执行以下操作:
<$ p $编译('org.springframework.boot:spring-boot-starter-data-jpa'){
exclude(module:'hibernate-core')
exclude(module :'hibernate-entitymanager')
}
但明白这一点, code> spring-data-jpa 你必须有一个像 hibernate
这样的持久化提供者,只是因为 spring- data-jpa
本身不过是 JPA
之上的抽象,而 hiberna te
或 eclipselink
。
更新
如果您想要将所有jpa依赖关系保留在gradle构建脚本中,但不希望 spring-boot
将它们用于有一阵子,你必须禁用 DataSourceAutoConfiguration
和 HibernateJpaAutoConfiguration
。
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
I am using spring boot and following is my gradle file
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')
}
while m adding in gradle file the following dependecy
org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE
its including bunch of other dependencies like hibernate n all that i don't need it for now(just wanted to use spring data jpa) which cause many other problem so how can i use only spring-data-jpa and its related dependency only ?
tried to disable like exclude = { HibernateJpaAutoConfiguration.class} but does't go well
Thnks in advance
The simplest solution I guess would be just to include spring-data-jpa
, not spring-boot-starter-data-jpa
:
compile('org.springframework.data:spring-data-jpa:2.0.0.M2')
Or if you're really want to left starter, than you might try to do something like:
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude(module: 'hibernate-core')
exclude(module: 'hibernate-entitymanager')
}
But understand this, in order to use spring-data-jpa
you have to have a persistent provider like hibernate
, just because spring-data-jpa
itself is nothing more than an abstraction on top of JPA
which in turn is an abstraction as well on top of persistent providers like hibernate
or eclipselink
.
Update
If you want to leave all jpa dependencies in gradle build script, but don't want spring-boot
to use them for a while, then you have to disable both DataSourceAutoConfiguration
and HibernateJpaAutoConfiguration
as well.
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
这篇关于如何从弹簧引导中排除依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!