异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.seing.eepsweb.service.company.CompanyService com.seing.eepsweb.web.company.CompanyController.companyService; nested exception is 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 method: public void com.seing.eepsweb.service.company.CompanyService.setCompanyDao(com.seing.eepsweb.repository.CompanyDao); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'companyDao': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property company found for type com.seing.eepsweb.entity.Company
发生异常的代码:
public interface CompanyDao extends PagingAndSortingRepository<Company, Long>, JpaSpecificationExecutor<Company> {
Page<Company> findByCompanyId(Long companyid,Pageable pageRequest);
}
解决原因和方法:
原因:No property company found for type com.seing.eepsweb.entity.Company
原理:在Page<Company> findByCompanyId(Long companyid,Pageable pageRequest); 中CompanyId一定要是Company实体类中的属性,否则使用自动注入@Autowired就无法通过。
所以把Page<Company> findByXXX(Long companyid,Pageable pageRequest);中的XXX改为Company实体类中的属性,或者删除:Page<Company> findByCompanyId(Long companyid,Pageable pageRequest); 就可以解决。