Mila
Mila

Reputation: 31

spring data elasticsearch Invocation of init method failed; nested exception is java.lang.AbstractMethodError

I have problem with Spring Data Elasticsearch. I configure elasticsearch like this:

@Configuration
@EnableJpaRepositories(basePackages = {"org.project.repositories"})
@EnableElasticsearchRepositories(basePackages = "org.project.repositorieselastic")
@EnableTransactionManagement
public class PersistenceContext {
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
    return new ElasticsearchTemplate(client());
}

@Bean
public Client client(){

    Settings settings = ImmutableSettings.settingsBuilder()
        // Setting "transport.type" enables this module:
        .put("cluster.name", "elasticsearch")
        .put("client.transport.ignore_cluster_name", false)
        .build();


    TransportClient client= new TransportClient(settings);
    TransportAddress address = new InetSocketTransportAddress("127.0.0.1", 9300);
    client.addTransportAddress(address);
    return client;
}

}

My repo looks like.

@Repository()
public interface UserFavoriteElasticRepo extends ElasticsearchRepository<UserFavorite, Long> {

}

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.project.repositorieselastic.UserFavoriteElasticRepo org.project.services.elastic.FavoriteIndexerService.elasticRepo; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userFavoriteElasticRepo': Invocation of init method failed; nested exception is java.lang.AbstractMethodError

It's look like the implementation is not generated. But I don't know where to investigate. I tried to use one package and use this - https://github.com/izeye/spring-boot-throwaway-branches/commit/874ccba09189d6ef897bc430c43b6e3705404399 but with no success.

Upvotes: 3

Views: 5223

Answers (2)

Pierpaolo Pagnoni
Pierpaolo Pagnoni

Reputation: 111

I solved the problem adding this in pom file

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>1.12.2.RELEASE</version>
</dependency>

Upvotes: 1

Bartosz Wardziński
Bartosz Wardziński

Reputation: 6593

I've got same exception using spring-data-elasticsearch. But exception was thrown when I declared new methods in repository: ex.:

public interface UserFavoriteElasticRepo extends ElasticsearchRepository<UserFavorite, Long> {
Page<UserFavorite> findBySomeProperty(String propertyValue, Pageable pageable);

}

It was casued due to spring-data-elasticsearch, spring-data-commons versions. Function declarations have changed: org.springframework.data.repository.query.QueryLookupStrategy.resolveQuery - it caused the exception. For spring-data-elasticsearch version 2.0.0.RELEASE you have to use spring-data-commons with version 1.12.0.
If you have spring-data-jpa in your project it also uses spring-data-commons. For spring-data-jpa v1.9.0.RELEASE, spring-data-commons is v1.11.0.RELEASE

Could you provide what frameworks and versions of spring you are using? Also If you could put whole stacktrace, it will be helpfull?

Upvotes: 0

Related Questions