2016-04-18 7 views
1

mongoコレクションからレコードを照会しようとしましたが、org.springframework.data.mongodb.core.MongoOperationsを使用しています。私はCompanyTemplRepoImplクラスのこの "List find(List industry、Pageable pageable)"のようなメソッドを定義します。実行エラーメッセージは次のように表示されます。メソッド名を "findByIndustry"に変更すると、エラーメッセージは消えてしまいますが、結果として常にリスト "[]"が表示されます。 私はすでに "public interface CompanyRepo extends MongoRepository、CompanyTemplRepo"で "findByIndustry"というメソッドを定義しました。クラスorg.springframework.beans.PropertyMatchesクラスorg.springframework.data.mapping.PropertyReferenceExceptionからアクセスしようとしました

1.CompanyTemplRepoインタフェース:

package com.chaoke.smart.repo; 

import java.util.List; 

import org.springframework.data.domain.Pageable; 

import com.chaoke.smart.jpa.data.IcmsCompany; 

public interface CompanyTemplRepo { 

    List<IcmsCompany> find(List<String> industries, Pageable pageable); 

} 

2.implクラス

package com.chaoke.smart.repo.impl; 

import static org.springframework.data.mongodb.core.query.Criteria.where; 
import static org.springframework.data.mongodb.core.query.Query.query; 

import java.util.List; 

import javax.annotation.Resource; 

import org.springframework.data.domain.Pageable; 
import org.springframework.data.mongodb.core.MongoOperations; 

import com.chaoke.smart.jpa.data.IcmsCompany; 
import com.chaoke.smart.repo.CompanyTemplRepo; 

public class CompanyTemplRepoImpl implements CompanyTemplRepo { 

    @Resource(name = "mongoTemplate") 
    private MongoOperations operations; 

    @Override 
    public List<IcmsCompany> find(List<String> industries, Pageable pageable) { 
     System.out.println("++++++++++++++++++++++++=========================="); 
     int pageNo = pageable.getPageNumber(); 
     int pageSize = pageable.getPageSize(); 
     return operations.find(query(where("industry").is("商务服务业")), 
       //in(industries)).skip(pageNo * pageSize).limit(pageSize), 
       IcmsCompany.class); 
    } 

} 

3.CompanyServiceインタフェース:

public interface CompanyService { 

    public List<CompanyListResult> getConcernCompanyListPageable(String account, String industry, int pn, int ps); 

    public IcmsCompany getConcernCompanyDetail(String companyId, String account); 

} 

4.

@Repository 
public interface CompanyRepo extends MongoRepository<IcmsCompany, String>, CompanyTemplRepo { 

    List<IcmsCompany> findByIndustry(String industry, Pageable pageable); 

    IcmsCompany findOneByCompanyId(Integer companyId); 

} 

5.service.impl

package com.chaoke.smart.service.impl; 

import java.util.ArrayList; 
import java.util.List; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.data.domain.PageRequest; 
import org.springframework.data.domain.Pageable; 
import org.springframework.stereotype.Service; 

import com.chaoke.smart.jpa.data.IcmsCompany; 
import com.chaoke.smart.jpa.data.IcmsFollowCompanyList; 
import com.chaoke.smart.model.CompanyListResult; 
import com.chaoke.smart.repo.CompanyRepo; 
import com.chaoke.smart.repo.FollowCompanyListRepo; 
import com.chaoke.smart.service.CompanyService; 

import lombok.Data; 

@Data 
@Service("companyService") 
public class CompanyServiceImpl implements CompanyService { 

    @Autowired 
    FollowCompanyListRepo followCompanyListRepo; 
    @Autowired 
    CompanyRepo companyRepo; 

    @Override 
    public List<CompanyListResult> getConcernCompanyListPageable(String account, String industry, int pn, int ps) { 
     List<CompanyListResult> resultList = new ArrayList<CompanyListResult>(); 
     try { 
      Pageable pageable = new PageRequest(pn, ps); 
      // 没有industry参数时,先查询客户关注的industry,然后根据industry查询company表。 
      if (industry == null || "".equals(industry)) { 
       List<IcmsFollowCompanyList> list1 = followCompanyListRepo.findByAcctId(Integer.valueOf(account)); 
       if (list1 != null && list1.size() > 0) { 
        ArrayList<String> indusList = new ArrayList<String>(); 
        for (IcmsFollowCompanyList icmsFollowCompanyList : list1) { 
         indusList.add(icmsFollowCompanyList.getIndustry()); 
        } 
        List<IcmsCompany> compList = companyRepo.find(indusList, pageable); 
        for (IcmsCompany icmsCompany : compList) { 
         CompanyListResult companyListResult = new CompanyListResult(); 
         companyListResult.setCompanyId(icmsCompany.getCompanyId()); 
         companyListResult.setCompanyName(icmsCompany.getCompanyName()); 
         resultList.add(companyListResult); 
        } 
       } 
       // 当传递industry参数时直接按industry查询company表。 
      } else { 
       List<IcmsCompany> compList = companyRepo.findByIndustry(industry, pageable); 
       for (IcmsCompany icmsCompany : compList) { 
        CompanyListResult companyListResult = new CompanyListResult(); 
        companyListResult.setCompanyId(icmsCompany.getCompanyId()); 
        companyListResult.setCompanyName(icmsCompany.getCompanyName()); 
        resultList.add(companyListResult); 
       } 
      } 

      return resultList; 
     } catch (Exception e) { 
      e.printStackTrace(); 
      return resultList; 
     } 
    } 

} 

エラーメッセージ:

2016-04-18 11:10:18,713 WARN [AbstractApplicationContext.java:487] : Exception encountered during context initialization - cancelling refresh attempt 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chaoke.smart.repo.CompanyRepo com.chaoke.smart.service.impl.CompanyServiceImpl.companyRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
     at com.chaoke.smart.service.Executable.<clinit>(Executable.java:21) 
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chaoke.smart.repo.CompanyRepo com.chaoke.smart.service.impl.CompanyServiceImpl.companyRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) 
     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 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) 
     ... 15 more 
    Caused by: java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.data.mapping.PropertyReferenceException.detectPotentialMatches(PropertyReferenceException.java:146) 
     at org.springframework.data.mapping.PropertyReferenceException.<init>(PropertyReferenceException.java:62) 
     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.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:54) 
     at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:159) 
     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.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) 
     ... 25 more 
    Exception in thread "main" java.lang.ExceptionInInitializerError 
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chaoke.smart.repo.CompanyRepo com.chaoke.smart.service.impl.CompanyServiceImpl.companyRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
     at com.chaoke.smart.service.Executable.<clinit>(Executable.java:21) 
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chaoke.smart.repo.CompanyRepo com.chaoke.smart.service.impl.CompanyServiceImpl.companyRepo; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561) 
     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 'companyRepo': Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) 
     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) 
     ... 15 more 
    Caused by: java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException 
     at org.springframework.data.mapping.PropertyReferenceException.detectPotentialMatches(PropertyReferenceException.java:146) 
     at org.springframework.data.mapping.PropertyReferenceException.<init>(PropertyReferenceException.java:62) 
     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.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:54) 
     at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:159) 
     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.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) 
     ... 25 more 

答えて

1

ばねデータにorg.springframework.data.mapping.PropertyReferenceException.detectPotentialMatchesで使用PropertyMatches.forFieldであった2つのメソッドを使用し豆のバージョン4.1.7に追加されました。あなたが4.1.7以上を使用していることを確認してください

0

org.springframwork.data.spring-data-mongodbの間違ったバージョンからこの問題が発生しました。私は問題を取り除くために1.8.4から1.9.3に行きました。

関連する問題