[英]spring data JPA & spring data elasticsearch; No property index found for type?
我不确定为什么会这样! 我有一个由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]
我有以下应用程序类:
@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的包搜索 ,如下所示:
public interface ArticleSearch extends ElasticsearchRepository<Article, String> {
我试图在另一个导致错误发生的服务中自动装入 articlesearch类:
@Autowired
ArticleSearch articleSearch;
我在这里想念的是什么?! 我想在尝试使用data-jpa + data-elasticsearch时会有点复杂。
我发现了为什么会这样。 我不知道为什么,但是Spring似乎没有拿起我的ElasticSearchConfiguration
配置类!
所以我只是移动了所有内容并将其转储到我的主应用程序类中(其他所有配置都是)。
我还删除了组件扫描并将enablejparepository + enableelasticsearchrepository注释添加到我的主类。 这是现在的样子:
@SpringBootApplication
@EnableAsync
@EnableElasticsearchRepositories(basePackages = "com.article.search")
@EnableJpaRepositories(basePackages = {"com.article.dao", "com.user.dao"})
public class ArticleApplication {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.