20

ssm配置elasticsearch问题

jdk1.8 + Myeclipse + spring4.0.2 + elasticsearch6.5.4(本地已能部署运行) 如下版本依赖

<dependency>
		    <groupId>org.elasticsearch</groupId>
		    <artifactId>elasticsearch</artifactId>
		    <version>6.5.4</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-elasticsearch -->
		<dependency>
		    <groupId>org.springframework.data</groupId>
		    <artifactId>spring-data-elasticsearch</artifactId>
		    <version>3.2.6.RELEASE</version>
		</dependency>
		
		<dependency>
	        <groupId>org.elasticsearch.client</groupId>
	        <artifactId>transport</artifactId>
	        <version>6.5.4</version>
	    </dependency>

xml配置文件加这三段就会出错,去掉就能正常运行

<!-- 搜索DAO 扫描 -->
    <elasticsearch:repositories base-package="com.esDao" elasticsearch-template-ref="elasticsearchTemplate"/>
 
    <!-- 配置Client -->
    <elasticsearch:transport-client id="client" cluster-nodes="127.0.0.1:9200"/>
 
    <!-- 配置搜索模板  -->
    <bean id="elasticsearchTemplate"
          class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="client" />
    </bean>

esDao下:

User:

package com.esDao;

import java.util.Date;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import com.fasterxml.jackson.annotation.JsonFormat;

@Document(indexName = "user_db", type = "user_table")
public class User{
    @Id
    @Field(type = FieldType.Keyword)
    private String userId;

    @Field(type= FieldType.Keyword)
    private String account; 

    @Field(type= FieldType.Keyword)
    private String userName;

    @Field(type= FieldType.Keyword)
    private String idCard; 

    @Field(type = FieldType.Date,
            format = DateFormat.custom,
            pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime; 
    //DOTO
    //get和set方法
    //toString()方法
}

UserRepository:

package com.esDao;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
public interface UserRepository extends ElasticsearchRepository<User, String> {
    void Main();
}

 项目启动后报错信息(大致意思应该是版本不对):

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getEnvironment()Lorg/springframework/core/env/Environment;

 

Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getEnvironment()Lorg/springframework/core/env/Environment;

真心求解,please

查看全部
qq_42862184
Mr_sswen
2020/12/01 19:31
  • spring
  • maven
  • 点赞
  • 收藏
  • 回答
    私信

6个回复