我正在使用Gradle(Spring Boot 1.4.2,Thymeleaf,Elasticsearch 2.3.4)并且我在本地工作。
我试图使用thymeleaf-extras-springsecurity4
模块实现Thymeleaf安全性,但我遇到了问题。
我收到了这个错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDashboardDaoImpl': Unsatisfied dependency expressed through field 'userDashboardRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDashboardRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: java.lang.IllegalStateException: failed to load bundle [file:/D:/elasticsearch-2.3.4/modules/lang-expression/antlr4-runtime-4.5.1-1.jar, file:/D:/elasticsearch-2.3.4/modules/lang-expression/asm-5.0.4.jar, file:/D:/elasticsearch-2.3.4/modules/lang-expression/asm-commons-5.0.4.jar, file:/D:/elasticsearch-2.3.4/modules/lang-expression/lang-expression-2.3.4.jar, file:/D:/elasticsearch-2.3.4/modules/lang-expression/lucene-expressions-5.5.0.jar] due to jar hell
我的build.gradle
是:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin: 1.4.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'Selva'
version = '0.1.0'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.4.2.RELEASE'
}
}
if (!hasProperty('mainClass')) {
ext.mainClass = '*.*.config.Application'
}
configurations {
provided
}
repositories {
mavenCentral()
maven {
url "http://jasperreports.sourceforge.net/maven2"
}
maven {
url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"
}
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.2.RELEASE'
compile group: 'com.h2database', name: 'h2', version: '1.4.193'
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.1'
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity4', version: '3.0.1.RELEASE'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
}
答案 0 :(得分:0)
这是因为JAR地狱。
您依赖org.springframework.boot:spring-boot-starter-data-elasticsearch:1.4.0.RELEASE'
导入org.springframework.data:spring-data-elasticsearch
,org.elasticsearch:elasticsearch
会导入org.elasticsearch:elasticsearch:2.3.4
。
除此之外,您直接导入spring-boot-starter-data-elasticsearch
,这意味着您最终将获得两个弹性搜索JAR,因此JAR地狱。
如果您正在使用org.elasticsearch:elasticsearch
,则无需为{{1}}拥有自己的导入功能。
删除它,你会没事的。