2016-11-25 101 views
0

我正在使用Gradle(Spring Boot 1.4.2,Thymeleaf,Elasticsearch 2.3.4),我在本地工作。 我试图使用thymeleaf-extras-springsecurity4模块来实现Thymeleaf安全性,但我遇到了一个问题。Elasticsearch配置未能加载包

我得到这个错误:

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

这是因为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,这意味着你最终会得到两个elasticsearch JAR,因此是JAR地狱。

如果您使用的是spring-boot-starter-data-elasticsearch,则无需为org.elasticsearch:elasticsearch自己导入。

删除它,你会没事的。

+0

你能测试吗? – Val