我试图用Grails 3.1.9项目连接Elasticsearch插件('org.grails.plugins:elasticsearch:1.4.1'),没有任何运气。
我还在github上传了一个简单的应用程序来演示问题(https://github.com/jackiebai/testEs)
上述示例测试应用程序只有一个名为 Person 的域名类:
class Person {
String name
static searchable = true
static constraints = {
}
}
相应的服务类 PersonService 用于保存和索引Person数据:
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 中添加了几行代码,以便在应用程序启动时将一些数据插入到默认的hibernate数据库中:
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: 客户: mode:节点 transport.sniff:是的 bulkIndexOnStartup:true datastoreImpl:hibernateDatastore
通过遵循插件用户指南(http://noamt.github.io/elasticsearch-grails-plugin/docs/index.html)
,build.gradle中包含其他依赖项和bootRun代码块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环境下运行,但错误如下:
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
答案 0 :(得分:2)
根据您使用的文档使用v1.2.0
答案 1 :(得分:0)
我认为版本1.4.1已被破坏。您可以使用Grails 3.3+尝试2.4.0.RC1,但是您需要向mapper-attachments
添加依赖项并为Spring Boot指定elasticsearch.version
:
ext['elasticsearch.version'] = '5.4.1'
dependencies {
compile 'org.grails.plugins:elasticsearch:2.4.0.RC1'
runtime 'org.elasticsearch.plugin:mapper-attachments:2.4.6'
}
请参阅issue#198