gpt4 book ai didi

Spring 数据 JPA 和 Spring 数据 Elasticsearch ;找不到类型的属性索引?

转载 作者:行者123 更新时间:2023-12-04 11:53:31 28 4
gpt4 key购买 nike

我不确定为什么会这样!我有一个由 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> {

我正在尝试 autowire 导致错误发生的另一个服务中的 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 {

关于 Spring 数据 JPA 和 Spring 数据 Elasticsearch ;找不到类型的属性索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39176866/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com