【问题标题】:spring data JPA & spring data elasticsearch; No property index found for type?弹簧数据 JPA 和弹簧数据弹性搜索;找不到类型的属性索引?
【发布时间】:2017-01-03 18:00:24
【问题描述】:

我不确定为什么会这样!我有一个由 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 的包 search,如下所示:

public interface ArticleSearch extends ElasticsearchRepository<Article, String> {

我正在尝试autowire另一个导致错误发生的服务中的 articlesearch 类:

@Autowired
ArticleSearch articleSearch;

我在这里错过了什么?!我想尝试使用 data-jpa + data-elasticsearch 时会更复杂一些。

【问题讨论】:

  • 你能把文章类的所有代码都显示出来吗?
  • 这是一个带有@列注释的标准休眠类。我没有添加任何弹性搜索注释@xierui
  • 我以前见过这个错误。我认为您可以先检查存储库中的方法或查询。一些方法如“findByIndex”会出现错误。
  • 由于错误日志显示 'articleSearch' ,我认为方法应该在 'articleSearch' 中。你最好把所有的代码都显示出来,这样我就可以看出它有什么问题了。
  • 仍然不知道发生了什么@xierui

标签: spring jpa spring-data spring-data-jpa spring-data-elasticsearch


【解决方案1】:

我发现了为什么会这样。我不知道为什么,但是 spring 似乎没有拿起我的ElasticSearchConfiguration 配置类!

所以我只是将所有内容从中移出并将其转储到我的主应用程序类中(我的所有其他配置都在其中)。

我还删除了组件扫描并将 enablejparepository + enableelasticsearchrepository 注释添加到我的主类中。这是它现在的样子:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 2014-08-16
    相关资源
    最近更新 更多