本文介绍了无法使Elasticsearch插件与Grails 3配合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Grails 3.1.9项目连接Elasticsearch插件(org.grails.plugins:elasticsearch:1.4.1'),但没有任何运气。

I've tried to hook up Elasticsearch plugin ('org.grails.plugins:elasticsearch:1.4.1') with a Grails 3.1.9 project without any luck.

我还在github中上传了一个简单的应用程序来演示该问题()

I've also uploaded a simple application in github to demonstrate the issue (https://github.com/jackiebai/testEs)

上面的示例测试应用只有一个域类,称为 Person

The above sample testing app only has 1 domain class called Person:

class Person {
    String name
    static searchable = true
    static constraints = {
    }
}

相应的服务类 PersonService 用于保存和索引Person数据:

The corresponding service class PersonService is used to save and index the Person data:

import grails.transaction.Transactional
@Transactional
class PersonService {
    def addPerson(Person person){
        person.save()
        person.index()
    }
    def addPerson(String name) {
        Person p = new Person(name:name)
        addPerson(p)
    }
}

我还添加了一个 BootStrap.groovy 中的许多行代码,以便在应用程序启动时将某些数据插入默认的休眠数据库中:

I've also added a couple of lines of code in the BootStrap.groovy so that some data will get inserted into the default hibernate db when the application starts:

class BootStrap {
    def personService
    def init = { servletContext ->
        personService.addPerson("Person One")
        personService.addPerson("John Smith")
    }
    def destroy = {
    }
}

开发环境的application.yml变量设置如下所示:
环境:
开发:
数据源:
dbCreate:create-drop
url:jdbc:h2:mem:devDb; MVCC = TRUE; LOCK_TIMEOUT = 10000; DB_CLOSE_ON_EXIT = FALSE
elasticSearch:
客户端:
模式:节点
transport.sniff:true
bulkIndexOnStartup:true
datastoreImpl:hibernateDatastore

The application.yml variable settings for the development environment look like below: environments: development: dataSource: dbCreate: create-drop url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE elasticSearch: client: mode: node transport.sniff: true bulkIndexOnStartup: true datastoreImpl: hibernateDatastore

通过遵循插件用户指南()

Additional dependencies and bootRun code block were included in the build.gradle by following the plugin user guide (http://noamt.github.io/elasticsearch-grails-plugin/docs/index.html)

dependencies {
    ...
    compile 'org.grails.plugins:elasticsearch:1.4.1'
    compile 'org.elasticsearch:elasticsearch:5.4.1'
    ...
}
bootRun{
    jvmArgs = ['-Des.path.home=/Users/myname/elasticsearch-5.4.1']
}

不幸的是,应用程序无法在我的osx 10.11.6,java 1.8.0_91环境下运行,并出现以下错误:

Unfortunately the application failed to run under my osx 10.11.6,java 1.8.0_91 environment with below errors:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticSearchClient': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/mapper/attachments/MapperAttachmentsPlugin
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1590)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 34 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/mapper/attachments/MapperAttachmentsPlugin
    at grails.plugins.elasticsearch.ClientNodeFactoryBean.getObject(ClientNodeFactoryBean.groovy:207)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
    ... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.mapper.attachments.MapperAttachmentsPlugin
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 41 common frames omitted


推荐答案

根据文档,您应该使用v1.2.0

According to documentation you should use v1.2.0

这篇关于无法使Elasticsearch插件与Grails 3配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 05:36