解决BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type XXX, but was actually of type XXX问题

  Java新手,困扰了一下午。

  发布时总是报这样一个错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXX': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type [XXXX], but was actually of type [XXXXX]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
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:294)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'XXX' must be of type [XXXX], but was actually of type [XXXXX]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:360)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:269)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

最后找到原因:action中引用的包名,与spring bean注册文件中注册的包不一致,导致action没有引用到目标包,反而引用一个错误的包(旧包)。

解决方法:确定要引用的新的包名,在action中去掉无错的import,重新import新的包。

posted @ 2016-12-13 18:27  果冻迪迪  阅读(17929)  评论(0编辑  收藏  举报