inewzone 2012-03-21 14:55
浏览 211
已采纳

大家过来看一看,瞧一瞧,有的spring报找不到xxxbean。。。纠结中!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileUploadService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'fileUploadDao' is defined
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at JUnit.test.ArticleInforServiceTest.setUpBeforeClass(ArticleInforServiceTest.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'fileUploadDao' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1056)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
    ... 28 more

部分源码:

 /**
 
  */
@Repository
public class FileUploadDAO extends BaseDAO<FileUpload> {

}

 model类

@Entity@Table(name="uploadfile")
public class FileUpload implements Serializable{
    /**
     * 文件上传
     */
    private static final long serialVersionUID = 7194554589429406803L;
    @Id @GeneratedValue
    private Integer id;
    @Column(nullable=false,length=80)
    private String filepath;
    @Temporal(TemporalType.TIMESTAMP)
    private Date uploadtime;
    
    public FileUpload()
    {
        
    }
    public FileUpload(String filepath) {
        this.filepath = filepath;
    }
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath;
    }

    public Date getUploadtime() {
        return uploadtime;
    }

    public void setUploadtime(Date uploadtime) {
        this.uploadtime = uploadtime;
    }

    
/**
接口类
*/
public interface IFileUploadService extends ServiceInterface<FileUpload> {
     public List<FileUpload> getFilePath(Integer[] ids);
     public List<FileUpload> findAllUploadFile();
     @SuppressWarnings("rawtypes")
    public Page findAllUploadFile(Page page,List<PropertyFilter> pfList);
@Component("fileUploadService")
public class FileUploadService extends BaseService<FileUpload>implements IFileUploadService {
  
    @Resource(name="fileUploadDao")
    //@Resource
    //@Qualifier("uploadFileDao")
    private DAOInterface<FileUpload> fileUploadDao;
    public List<FileUpload> getFilePath(Integer[] ids) {
        // TODO Auto-generated method stub
        if(ids!=null && ids.length>0){
            StringBuffer jpql = new StringBuffer();
            String hql;
            for(int i=0; i<ids.length;i++){
                jpql.append('?').append((i+1)).append(',');
            }
            jpql.deleteCharAt(jpql.length()-1);
            hql=" select o.filepath from UploadFile o where o.id in("+ jpql.toString()+ ")";
            return null;
        }

        return null;
    }

    
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public Page findAllUploadFile(Page page, List<PropertyFilter> pfList) {
        //初始化hql
        StringBuffer hql=new StringBuffer("from UploadFile");
        //设置查询条件
        String condition= QueryUtil.toSqlString(pfList, true);
        hql.append(condition);
        //查找所有用户的总条数
        int totalCount=this.fileUploadDao.findCountBySql(hql.toString());
        page.setTotalCount(totalCount);
        
        
        //是否存在排序
        if(page.isOrderBySetted()){
            hql.append(page.getOrder());
        }
        List<FileUpload> list=this.fileUploadDao.findList(hql.toString(), page.getPageNo(), page.getPageSize());
        //查出结果集
        page.setResult(list);
    
        return page;
    }
    public List<FileUpload> findAllUploadFile() {
        String hql="from UploadFile";
        return this.fileUploadDao.findList(hql);
    }


    public DAOInterface<FileUpload> getFileUploadDao() {
        return fileUploadDao;
    }


    public void setFileUploadDao(DAOInterface<FileUpload> fileUploadDao) {
        this.fileUploadDao = fileUploadDao;
    }
    @Override
    protected DAOInterface<FileUpload> getDAO() {
        // TODO Auto-generated method stub
        return fileUploadDao;
    }
  • 写回答

1条回答 默认 最新

  • qiankun123456 2012-03-21 16:13
    关注

    @Repository("fileUploadDao")
    public class FileUploadDAO extends BaseDAO {

    }试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?