springside4中@Autowired无法通过

异常:

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); 就可以解决。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值