mahfuj asif
mahfuj asif

Reputation: 1989

Can not use ElasticsearchRepository in spring boot

I am trying to use ElasticsearchRepository for simple CRUD operation. I dont want to use RestHighLevelClient. I was following this tutorials 1st method. Here is my dependancy

    implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'

And properties in Application.properties

spring.elasticsearch.rest.uris=http://192.168.5.212:9200
spring.elasticsearch.rest.connection-timeout=10s
spring.elasticsearch.rest.read-timeout=1m
spring.elasticsearch.rest.username=user
spring.elasticsearch.rest.password=pass

Then i just added repository

@Repository
public interface UserRepo extends ElasticsearchRepository<User, String> {

}

Finally here is my User class

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Document(createIndex = false, indexName = "user", type = "_doc")

public class User implements Serializable {

    @Id
    private String uid;

    private String name;
}

But i am getting the error

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-07 10:16:30,497 ERROR [main] o.s.b.d.LoggingFailureAnalysisReporter:40 - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in com.user.UserService required a bean named 'elasticsearchTemplate' that could not be found.


Action:

Consider defining a bean named 'elasticsearchTemplate' in your configuration.


Tried #spring.data.elasticsearch.repositories.enabled = true but still getting error

N.B This question is not a duplicate of This question as i am using different method.

Upvotes: 2

Views: 1348

Answers (1)

mahfuj asif
mahfuj asif

Reputation: 1989

Solved my problem, The issue is my springboot project version is '2.1.8.RELEASE'. The autoconfiguration i am trying to implement requires minimum spring boot version 2.2.0. As i can not upgrade spring boot version, i had to add configuration class manually.

Upvotes: 2

Related Questions