我不确定为什么会发生这种情况!我有一个类被Spring Data Elasticsearch和Spring Data JPA使用,但是当我尝试运行我的应用程序时,出现了错误。
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've got the following application class:
@SpringBootApplication
@EnableAsync
@ComponentScan(basePackages = {"com.article.models", "com.user"})
public class ArticleApplication {
以下是elasticsearch的配置:
@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());
}
}
这是我设置模型类的方式:
@Entity
@Table(name="article")
@Document(indexName="article", type="articles")
public class Article implements Serializable {
我有一个扩展了elasticsearchrepository的包search,如下所示:
public interface ArticleSearch extends ElasticsearchRepository<Article, String> {
我正在尝试在另一个服务中自动装配文章搜索类,这导致错误发生:
@Autowired
ArticleSearch articleSearch;
我在这里漏掉了什么?!当尝试使用data-jpa + data-elasticsearch时,可能会更加复杂。