2015-04-24 5 views
0

Перед тем, как настроить весовые данные elasticsearch, я столкнулся с процедурой, упомянутой здесь Spring bean configuration for Crud Repositories. Но я получаю сообщение об ошибке:Конфигурация CRUD для данных весны данных

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepo': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [spring-repository.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.elasticsearch.core.ElasticsearchTemplate]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z

Вот код:

CustomerService.java

@Service 
public class CustomerService { 
@Resource 
CustomerRepo custRepo; 

public void save(Customer cust) { 
    custRepo.save(cust); 
} 
} 

Customer.java

@Document(
     indexName = "Customer", type = "cust" 
     ) 
public class Customer { 

@Id 
private String id; 
private String name; 

public Customer(String name) { 
    this.name = name; 
} 

public String getName() { 
    return this.name; 
} 
public String getId() { 
    return id; 
} 

public void setId(String id) { 
    this.id = id; 
} 
} 

CustomerRepo.java

public interface CustomerRepo extends ElasticsearchRepository<Customer, String> { 
} 

MainClass.java

public class MainClass { 
public static void main(String args[]) { 
    ApplicationContext context = 
      new ClassPathXmlApplicationContext(new String[] {"spring-customer.xml"}); 
    CustomerService cust = (CustomerService)context.getBean("CustomerService"); 
    Customer customer = new Customer("test_name"); 
    cust.save(customer); 
} 
} 

весна-customer.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd"> 
<context:component-scan base-package="com.elasticsearch" /> 

<import resource="spring-repository.xml"/> 

</beans> 

весна-repository.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch" 
    xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch 
    http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> 

<elasticsearch:transport-client id="client" cluster-nodes="xx.xx.xx.xx:9200" /> 

<bean name="elasticsearchTemplate" 
     class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate"> 
    <constructor-arg name="client" ref="client" /> 
</bean> 

<elasticsearch:repositories 
     base-package="com.elasticsearch.repositories" /> 

Я не знаю, почему он не работает. Пожалуйста, помогите мне.

ответ

0

Он работал, наконец, после изменения этих файлов:

1) весна-customer.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd"> 
<context:component-scan base-package="com.elasticsearch.repositories" /> 

<import resource="spring-repository.xml"/> 
<bean id="customerService" class="com.elasticsearch.CustomerService" scope="prototype" > 
     <property name="custRepo" ref="custRepo"></property> 
</bean> 
</beans> 

2) не Изменение порта нет. от 9200 до 9300 в spring-repository.xml. Поскольку 9200 для http, где 9300 для связи между узлами и узлами.

3) Добавление геттера и сеттера для custRepo в файле CustomerService.java.

Смежные вопросы