【问题标题】:Elasticsearch configuration failed to load bundleElasticsearch 配置加载包失败
【发布时间】:2016-11-25 14:11:44
【问题描述】:

我正在使用 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'
 }

【问题讨论】:

    标签: elasticsearch gradle spring-security spring-boot


    【解决方案1】:

    这是因为 JAR 地狱。

    您依赖于org.springframework.boot:spring-boot-starter-data-elasticsearch:1.4.0.RELEASE',它将导入org.springframework.data:spring-data-elasticsearch,而org.springframework.data:spring-data-elasticsearch 又导入org.elasticsearch:elasticsearch

    除此之外,您将直接导入 org.elasticsearch:elasticsearch:2.3.4,这意味着您最终会得到两个弹性搜索 JAR,因此是 JAR 地狱。

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

    删除它,你会没事的。

    【讨论】:

    • 你能测试一下吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2012-12-29
    相关资源
    最近更新 更多