sách gpt4 ai đã đi

Spring Data JPA và Spring Data Elasticsearch; Không tìm thấy chỉ mục cho thuộc tính của loại?

In lại 作者:行者123 更新时间:2023-12-04 11:53:31 30 4
mua khóa gpt4 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.(PropertyPath.java:77) ~[spring-data-commons-1.11.4.RELEASE.jar:na]

我有以下应用程序类:
@SpringBootỨng dụng
@EnableAsync
@ComponentScan(basePackages = {"com.article.models", "com.user"})
public class ArticleApplication {

以及以下 Elasticsearch 配置:
@Cấu hình
@EnableElasticsearchRepositories(basePackages = "com.article.search")
public class ElasticSearchConfiguration {
@Tài nguyên
private Environment environment;

@Đậu
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;
}

@Đậu
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
}
}

这是我设置模型类的方式:
@Entity
@Table(name="article")
@Document(indexName="article", type="articles")

public class Article implements Serializable {

然后我得到了一个包裹 tìm kiếm Phần mở rộng elasticsearchrepository ,像这样:
public interface ArticleSearch extends ElasticsearchRepository {

Tôi đang cố gắng autowire 导致错误发生的另一个服务中的 articlesearch 类:
@Autowired
ArticleSearch articleSearch;

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

1 Câu trả lời

我发现了为什么会这样。我不知道为什么,但 Spring 似乎没有恢复我的 ElasticSearchConfiguration配置类!

所以我简单地移动了所有内容并将其转储到我的主应用程序类中(我所有其他配置所在的位置)。

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

@SpringBootỨng dụng
@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/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com