Spring JPA data & spring elasticsearch data; No property index found for type?

I'm not sure why this is happening! I have a class that uses spring data elasticsearch and spring data jpa, but when I try to run my application, I get an error.

Error creating bean with name 'articleSearch': 
Invocation of init method failed; nested exception is 
org.springframework.data.mapping.PropertyReferenceException: 
No property index found for type Article!

Caused by: org.springframework.data.mapping.PropertyReferenceException: 
No property index found for type Article!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.11.4.RELEASE.jar:na]

I have the following application class:

@SpringBootApplication
@EnableAsync
@ComponentScan(basePackages = {"com.article.models", "com.user"})
public class ArticleApplication {

And the following elasticsearch configuration:

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.article.search")
public class ElasticSearchConfiguration {
    @Resource
    private Environment environment;

    @Bean
    public Client client() {
        TransportClient client = new TransportClient();
        TransportAddress address = new InetSocketTransportAddress(environment.getProperty("elasticsearch.host"), Integer.parseInt(environment.getProperty("elasticsearch.port")));
        client.addTransportAddress(address);
        return client;
    }

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

This is how I set up the model class:

@Entity
@Table(name="article")
@Document(indexName="article", type="articles")

public class Article implements Serializable {

Then I got a search package that extends elasticsearchrepository , for example:

public interface ArticleSearch extends ElasticsearchRepository<Article, String> {

I am trying to autowire the articlesearch class inside another service that is throwing an error:

@Autowired
ArticleSearch articleSearch;

What am I missing here ?! I think this is a little more complicated when trying to use data-jpa + data-elasticsearch.

+4
1

, . , , spring, , ElasticSearchConfiguration!

, ( ).

enablejparepository + enableelasticsearchrepository . :

@SpringBootApplication
@EnableAsync
@EnableElasticsearchRepositories(basePackages = "com.article.search")
@EnableJpaRepositories(basePackages = {"com.article.dao", "com.user.dao"})
public class ArticleApplication {
+2

Source: https://habr.com/ru/post/1652671/


All Articles