service層
@Service
public class AuthorAdminServiceImpl implements IAuthorAdminService {
@Resource
private IAuthorAdminDao iauthoradmindao;
@Resource
PageUntil<AuthorAdmin> pageUntil;
@Override
public PageUntil<AuthorAdmin> findByPage(int currentPage) {
pageUntil.setCurrentPage(currentPage);// 當前多少頁
int pageSize = 3;
pageUntil.setPagesize(pageSize);// 最多顯示多少記錄
int totalCount = iauthoradmindao.findCount();// 數(shù)據(jù)庫中所有的記錄
pageUntil.setTotalCount(totalCount);
double tc = totalCount;
Double num = Math.ceil(tc / pageSize);// 頁面顯示的總頁數(shù)=數(shù)據(jù)庫的總記錄數(shù)/最多顯示多少記錄
pageUntil.setTotalPage(num.intValue());
int begin = (currentPage - 1) * pageSize;// 當前頁開頭位置的索引
List<AuthorAdmin> list = iauthoradmindao.findByPage(begin, pageSize);
if(list==null){
System.out.println("list findByPage service error");}
pageUntil.setList(list);
return pageUntil;
}
action層
public String listAuthorAdmin() {
PageUntil<AuthorAdmin> pageuntil = iauthoradminservice
.findByPage(currentPage);
ActionContext.getContext().getValueStack().push(pageuntil);
return "listSuccess";
}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
----------
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authorAdminServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
----------
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.lcy.until.PageUntil com.lcy.service.author.admin.AuthorAdminServiceImpl.pageUntil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
----------
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.lcy.until.PageUntil] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
如果不是使用注入而使用new的方法就行,請問為什麼?
閉關修行中......
你沒有正確使用@Resource,導致設定檔裡面找不到名稱屬性為"iauthoradmindao"的
詳情參考:https://www.zhihu.com/questio...