Jam*_*111 6 spring jpa spring-data spring-data-jpa spring-data-elasticsearch
我不确定为什么会这样!我有一个由 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]
Run Code Online (Sandbox Code Playgroud)
我有以下应用程序类:
@SpringBootApplication
@EnableAsync
@ComponentScan(basePackages = {"com.article.models", "com.user"})
public class ArticleApplication {
Run Code Online (Sandbox Code Playgroud)
以及以下弹性搜索配置:
@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());
}
}
Run Code Online (Sandbox Code Playgroud)
这是我设置模型类的方式:
@Entity
@Table(name="article")
@Document(indexName="article", type="articles")
public class Article implements Serializable {
Run Code Online (Sandbox Code Playgroud)
然后我有一个扩展elasticsearchrepository的包搜索,如下所示:
public interface ArticleSearch extends ElasticsearchRepository<Article, String> {
Run Code Online (Sandbox Code Playgroud)
我正在尝试在另一个导致错误发生的服务中自动装配articlesearch 类:
@Autowired
ArticleSearch articleSearch;
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?!我想尝试使用 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 {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3087 次 |
| 最近记录: |