简体   繁体   English

Spring Data MongDB 2.1.0中的PropertyReferenceException

[英]PropertyReferenceException in spring data mongdb 2.1.0

I am using spring data mongdb 2.1.0. 我正在使用spring数据mongdb 2.1.0。 And have custom implementation of repository as given below: 并具有如下所示的自定义存储库实现:

public class ProductItemRepositoryImpl implements ProductItemRepositoryCustom {


  @Override
  public List<String> getItemIdsGivenSkuOrCode(String itemIdType, String itemId) {
    Query query = new Query();
    query.addCriteria(Criteria.where(itemIdType).is(itemId));
    return mongoTemplate
        .findDistinct(query, FieldNames.PRODUCT_ITEM_ID, ProductItem.COLLECTION_NAME,
            String.class);
  }
} 

Custom repo : 自定义仓库:

public interface ProductItemRepositoryCustom {
  List<String> getItemIdsGivenSkuOrCode(String itemIdType, String itemId);
}

Repo : 回购:

public interface ProductItemRepository
    extends MongoRepository<ProductItem, Long>, ProductItemRepositoryCustom {
}

I dont understand why it is considering custom method(getItemIdsGivenSkuOrCode) as property. 我不明白为什么它考虑将自定义方法(getItemIdsGivenSkuOrCode)作为属性。 When i am running this, getting below given error : 当我运行此命令时,出现以下给定错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productItemRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property getItemIdsGivenSku found for type ProductItem!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:740) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]

I think it has to do something with method naming 我认为它必须与方法命名有关

Assuming your fields in ProductItem are 假设您在ProductItem中的字段是

String itemIdType;
String itemId;

Method Name would be 方法名称为

public interface ProductItemRepositoryCustom {
  List<String> findByItemIdTypeOrItemId(String itemIdType, String itemId);
}

or to be on safer side you can add query 为了安全起见,您可以添加查询

@Query("{ 'itemIdType': ?0, 'itemId': ?1}")
public List<String> findByItemIdTypeOrItemId(String itemIdType, String itemId);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data JPA findAll与介于两者之间的表(PropertyReferenceException) - Spring Data JPA findAll with table in between (PropertyReferenceException) Spring Boot 1.5.8.Release-Spring Data Mongo PropertyReferenceException - Spring Boot 1.5.8.Release - Spring Data Mongo PropertyReferenceException Spring Data Envers-PropertyReferenceException:找不到属性Foo类型的修订版 - Spring Data Envers - PropertyReferenceException: No property findRevisions found for type Foo Spring-data-neo4j + @Query抛出PropertyReferenceException - Spring-data-neo4j + @Query throws PropertyReferenceException 如何在Spring Data Mongo DB中聚合嵌套对象并避免PropertyReferenceException? - How to aggregate in spring data mongo db a nested object and avoid a PropertyReferenceException? 创建自定义存储库时的spring-data-neo4j PropertyReferenceException - spring-data-neo4j PropertyReferenceException when creating custom repository spring jpa 可分页排序 PropertyReferenceException - spring jpa pageable sort PropertyReferenceException Spring 数据 Rest 错误:原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型项目的属性名称 - Spring Data Rest error: Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Project Spring Data自定义方法错误:org.springframework.data.mapping.PropertyReferenceException:找不到类型的属性xxx - Spring Data Custom Method Error : org.springframework.data.mapping.PropertyReferenceException: No property xxx found for type Java Spring-boot 原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型的属性 ID - Java Spring-boot caused by: org.springframework.data.mapping.PropertyReferenceException: No property id found for type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM