升级到elasticsearch 5.5.0和spring-data-elastic-version 3.0.2:ClassNotFoundException:org.springframework.data.querydsl.QuerydslUtils

时间:2017-12-05 07:40:06

标签: elasticsearch spring-boot spring-data-elasticsearch

我正在尝试升级使用spring boot和spring data elasticsearch的应用程序。

  

spring boot-> 1.5.8.RELEASE从1.5.2.RELEASE   spring-data-elastic-version - > 3.0.2.RELEASE来自2.1.3.RELEASE

这是我的主要应用程序文件代码(与elasticsearch相关):

@SpringBootApplication
@EnableElasticsearchRepositories(basePackages = "org/springframework/data/elasticsearch/repositories")
 public class TeyeApplication extends WebMvcConfigurerAdapter {

@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
return new ElasticsearchTemplate(client());
}

@Bean
public Client client() throws UnknownHostException {
Settings settings =Settings.builder().put("cluster.name", "elasticsearch").build();
Client client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
return client;
}

当我运行应用程序时,它会出现以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'whiteListRepository': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/querydsl/QuerydslUtils
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 61 common frames omitted

Caused by: java.lang.NoClassDefFoundError: org/springframework/data/querydsl/QuerydslUtils
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory.isQueryDslRepository(ElasticsearchRepositoryFactory.java:95)
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory.getRepositoryBaseClass(ElasticsearchRepositoryFactory.java:79)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryInformation(RepositoryFactorySupport.java:253)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:195)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean.afterPropertiesSet(ElasticsearchRepositoryFactoryBean.java:67)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 72 common frames omitted

Caused by: java.lang.ClassNotFoundException: org.springframework.data.querydsl.QuerydslUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 81 common frames omitted

我试图解决这个问题将近3天,但无法找到解决方案。

修改

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.data</groupId>
                    <artifactId>spring-data-elasticsearch</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-elasticsearch -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-elasticsearch</artifactId>
            <version>3.0.2.RELEASE</version>
   </dependency>

0 个答案:

没有答案