未找到 User 类型的属性索引

2024-01-23

我正在尝试在同一个项目中将 ElasticSearch 与 MySQL 一起使用。 我在不同的项目中定义了两个存储库,但我总是收到此错误消息:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.services.UserServices com.owish.controllers.UserController.userServices; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.repositories.search.UserSearchRepo com.owish.services.UserServices.userSearchRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userSearchRepo': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.owish.services.AppServices.main(AppServices.java:25)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.services.UserServices com.owish.controllers.UserController.userServices; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.repositories.search.UserSearchRepo com.owish.services.UserServices.userSearchRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userSearchRepo': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 13 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.repositories.search.UserSearchRepo com.owish.services.UserServices.userSearchRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userSearchRepo': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 15 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.owish.repositories.search.UserSearchRepo com.owish.services.UserServices.userSearchRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userSearchRepo': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userSearchRepo': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 28 more
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property index found for type User!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:62)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:100)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:416)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 38 more

当我刚刚使用JpaRepository我没问题。 仅当我添加另一个扩展的存储库时,我才遇到这个问题ElasticsearchRepository。 JPA和Elasticsearch的接口定义是在不同的包中定义的。 我正在使用弹性搜索 2.2.1 和 Spring data elasticsearch 1.3.4 我认为这是一个配置问题。 下面是我正在使用的应用程序配置。如果我遗漏了什么,你能告诉我吗:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa 
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/data/elasticsearch
http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd">

<context:component-scan base-package="com.owish." />

<elasticsearch:node-client id="client" local="true" />
<elasticsearch:repositories base-package="com.owish.repositories.search" />
<elasticsearch:transport-client id="client"
    cluster-nodes="localhost:9200,someip:9200" />


<bean class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" id="dataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    <property name="url" value="jdbc:mysql://localhost:3306/owish"></property>
    <property name="username" value="root"></property>
    <property name="password" value="root"></property>
</bean>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true"></property>
            <property name="database" value="MYSQL"></property>
        </bean>
    </property>
    <property name="packagesToScan" value="com.owish.model" />
    <property name="persistenceUnitName" value="jpa.sample"></property>
</bean>
<!-- Configure the transaction manager bean -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<jpa:repositories base-package="com.owish.repositories" />
<!-- Enable annotation driven transaction management -->
<tx:annotation-driven />

我的用户实体声明如下:

@Entity
@Table (name ="user")
@Document(indexName = "user")
public class User {

@Id
@Column (name = "id") 
@GeneratedValue (strategy = GenerationType.AUTO)
private long id;
@Column (name = "username", nullable = false)
private String username;
@Column (name = "password", nullable = false)
private String password;

我的 ElasticSearch 存储库定义如下:

@Repository
public interface UserSearchRepo extends ElasticsearchRepository<User, Long> {
User findByUsername(String username);
List<User> findAllByOrderById ();
}

和我的 JPA 存储库

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}

ElasticsearchRepository http://docs.spring.io/spring-data/elasticsearch/docs/current/api/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.html#index-S-有一个名为index,这没有什么坏处,但是既然你确实把你的ElasticSearch 存储库 in com.owish.repositories.search包,它将被扫描Spring Data JPA 扫描器:

<jpa:repositories base-package="com.owish.repositories" />

因此,Spring Data JPA 会尝试代理您的UserSearchRepo并且找不到任何名为index in the User类,因此出现错误:

未找到用户类型的属性索引!

无论如何,如果您将 ElasticSearch 存储库从com.owish.repositories包及其子包,就可以了。例如,您可以将 ElasticSearch 存储库移至com.owish.search并且:

<elasticsearch:repositories base-package="com.owish.search" />

一句建议,尝试定义适用于应用程序的每个架构方面的一种配置,例如一个用于数据,一个用于网络,一个用于安全,并且每个中只放置相关配置。我没有得到这个组件扫描仪在你的角色数据访问相关配置:

<context:component-scan base-package="com.owish." />

也许为了让您的应用程序启动并运行这是必要的,但我严重怀疑这属于配置这一事实。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未找到 User 类型的属性索引 的相关文章

随机推荐

  • 如何向 iOS 14 小部件添加按钮

    我正在尝试向具有系列类型 systemLarge 的小部件添加按钮 我想在不打开应用程序的情况下执行一些代码 有人知道该怎么做吗 例如 快捷方式应用程序小部件包含您可以点击以执行快捷方式而无需打开应用程序的按钮 小部件是只读的 快捷方式应用
  • 使用 ElasticSearch 术语聚合动态创建的存储桶构建 Kibana 直方图

    我希望能够结合Kibana 术语图 能够根据特定属性值的唯一性创建存储桶 以及直方图 根据查询将数据分成桶 然后根据时间说明日期 总的来说 我想创建一个直方图 但我只想根据一个查询的结果创建直方图 而不是像在Kibana 演示应用程序 ht
  • IE10有flex-grow吗?

    Caniuse 使用 ms 前缀表示部分支持http caniuse com search flex grow http caniuse com search flex grow据我所知 然而 当测试 ms flex grow 在 IE10
  • 使用 OpenCV 检测越线人员

    我想统计从两边越线的人数 我有一个放置在天花板上的摄像机 拍摄线条所在的地板 因此摄像机只能看到人的头顶 因此它更多的是物体检测而不是人检测 是否有针对此问题或类似问题的示例解决方案 那我可以向他们学习吗 编辑1 任何时刻都有不止一个人越线
  • python:从字符串模板中提取变量

    我熟悉使用将变量插入字符串的能力模板 https docs python org 2 library string html template strings 像这样 Template value is between min and ma
  • 如何判断该点是否在四面体中?

    我知道四面体的所有坐标和我想确定的点 那么有人知道该怎么做吗 我试图确定该点属于四面体的每个三角形 如果它对所有三角形都成立 则该点位于四面体中 但这绝对是错误的 对于四面体的每个平面 检查该点是否与其余顶点位于同一侧 bool SameS
  • dplyr 中字符串的新列[重复]

    这个问题在这里已经有答案了 我有一个数据框 library tidyverse df lt tribble col1 col2 1 2 现在我想创建一个专栏 我有一个字符串中的新列的名称 它确实像这样工作 df gt mutate col3
  • 可以在运行时将目录添加到类路径中吗?

    为了更好地理解 Java 中的工作原理 我想知道是否可以在运行时动态地将目录添加到类路径中 例如 如果我启动一个 jar using java jar mycp jar 并输出java class path财产 我可能会得到 java cl
  • 类型错误:+ 不支持的操作数类型:“生成器”和“生成器”

    我在目标函数中添加三个表达式时遇到问题 我用了quicksum构建每个表达式 但是 当我尝试将它们添加在一起时 出现错误 无法在 生成器 类上使用 操作数 这是我的代码的最后一部分 the shipping cost expression
  • Angular是否需要取消订阅this.activatedRoute订阅

    My code ngOnInit this activatedRoute params subscribe params Params gt do stuff this activatedRoute data subscribe data
  • Builders 页面从 Eclipse 项目属性中消失

    我不知道我的带有最新 Android SDK 和最新 Sequoyah 插件的 Eclipse Helios 发生了什么 突然 我在项目属性中看不到 构建器 页面 不是工作区中的单个项目 我怎样才能恢复这个页面 检查您目前处于哪个视角 右上
  • 如何处理ETIMEDOUT错误?

    如何处理此调用的 etimedout 错误 var remotePath myremoteurltocopy var localStream fs createWriteStream myfil var out request uri re
  • 在Linux中设置Mysql++

    我想在linux中用C 连接mysql数据库 在我的本地计算机上 我运行 Ubuntu 并安装了 mysql 服务器和客户端软件包 sudo apt get install mysql server mysql client 我碰到Mysq
  • 有什么方法可以获得断点特定的宽度类吗?

    Bootstrap 4 包括宽度类别 https getbootstrap com docs 4 0 utilities sizing w 25 w 50 w 75 w 100 我只想为某些断点及以上指定宽度 例如 w md 25 等 是否
  • 在电子邮件正文中显示 Python HTML 表

    我编写了一个 python 脚本来查询数据库并以 HTML 表格式显示数据 我怎样才能让这个代码以表格的形式显示在电子邮件中 我尝试将代码粘贴到第二个脚本 EMAIL 的 html 标签内 但它不读取 python 代码 仅读取 HTML
  • CUDA 点积

    我正在做一个 cuda 教程 其中我必须制作两个向量的点积 实施教程中提供的解决方案后 我遇到了一些问题 这些问题已在this https stackoverflow com questions 15822412 dot product i
  • Rails Devise:如何(mem)缓存设备对用户对象的数据库请求?

    每次我点击经过身份验证的页面时 我都会注意到设计发出一条 SQL 语句 用户负载 0 2ms 选择users FROM users WHERE users id 1 限制 1 顺便说一句 我正在使用Rails 3 所以cache money
  • 为 DividerItemDecoration 设置可绘制对象

    我正在尝试为 DividerItemDecoration 设置自定义可绘制 线 但没有成功 错误在哪里 DividerItemDecoration dividerItemDecoration new DividerItemDecoratio
  • 垃圾收集:对象属性

    假设我有一个对象 其中包含另一个对象作为其属性 例如 var obj 1 42 When obj超出范围 所有嵌套对象是否都隐式销毁 或者我需要迭代它们并且delete明确地 是的 除非另一个参考仍然存在 var obj 1 42 var
  • 未找到 User 类型的属性索引

    我正在尝试在同一个项目中将 ElasticSearch 与 MySQL 一起使用 我在不同的项目中定义了两个存储库 但我总是收到此错误消息 Exception in thread main org springframework beans