开发者社区> 问答> 正文

Spring 启动时候报错?报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' must be of type [cn.tax.nsfw.user.dao.UserDao], but was actually of type [cn.tax.nsfw.user.dao.impl.UserDaoImpl]
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.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' must be of type [cn.tax.nsfw.user.dao.UserDao], but was actually of type [cn.tax.nsfw.user.dao.impl.UserDaoImpl]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
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)
... 27 more
2016-8-1 9:41:23 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' must be of type [cn.tax.nsfw.user.dao.UserDao], but was actually of type [cn.tax.nsfw.user.dao.impl.UserDaoImpl]
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.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' must be of type [cn.tax.nsfw.user.dao.UserDao], but was actually of type [cn.tax.nsfw.user.dao.impl.UserDaoImpl]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
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)
... 27 more
2016-8-1 9:41:24 com.sun.faces.config.ConfigureListener contextInitialized
信息: 初始化上下文 '/Tax' 的 Mojarra 2.0.3 (FCS b03)
2016-8-1 9:41:24 com.sun.faces.spi.InjectionProviderFactory createInstance
信息: JSF1048:有 PostConstruct/PreDestroy 注释。标有这些注释的 ManagedBeans 方法将表示注释已处理。
2016-8-1 9:41:24 org.apache.catalina.core.StandardContext startInternal
严重: One or more listeners failed to start. Full details will be found in the appropriate container log file
2016-8-1 9:41:24 org.apache.catalina.core.StandardContext startInternal
严重: Context [/Tax] startup failed due to previous errors
2016-8-1 9:41:24 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2016-8-1 9:41:24 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
严重: The web application [/Tax] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2016-8-1 9:41:24 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
严重: The web application [/Tax] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
2016-8-1 9:41:24 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory E:\apache-tomcat-7.0.70\webapps\Tax has finished in 3,725 ms
2016-8-1 9:41:24 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-8080"]
2016-8-1 9:41:24 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
2016-8-1 9:41:24 org.apache.catalina.startup.Catalina start

信息: Server startup in 4328 ms

上面是错误信息,我会贴出目录结构,以及相应的配置。

user-spring

user-struts

ApplicationContext

stuts

希望各位大神帮忙解答

展开
收起
爱吃鱼的程序员 2020-06-09 12:39:31 917 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    Causedby:org.springframework.beans.factory.BeanNotOfRequiredTypeException:Beannamed'userDao'mustbeoftype[cn.tax.nsfw.user.dao.UserDao],butwasactuallyoftype[cn.tax.nsfw.user.dao.impl.UserDaoImpl]这个地方我该了没用,谢谢您!你的userDAOImpl忘了实现userDAO接口了吧。。好好检查下你的代码 不是的,我是写了一个baseDao,然后继承,并实现UserDao

    第一句话说得很清楚了,userDao,你看看是不是像楼上说的那样。


    我把Dao贴出来给你们看看,谢谢你们的帮助<preclass="brush:java;toolbar:true;auto-links:false;">publicabstractclassBaseDaoImpl<T>extendsHibernateDaoSupportimplementsBaseDao<T>{Class<T>clazz;publicBaseDaoImpl(){ParameterizedTypept=(ParameterizedType)this.getClass().getGenericSuperclass();//BaseDaoImpl<User>clazz=(Class<T>)pt.getActualTypeArguments()[0];//获取范型类的第一个参数类}@Overridepublicvoidsave(Tentity){getHibernateTemplate().save(entity);}@Overridepublicvoidupdate(Tentity){getHibernateTemplate().update(entity);}@Overridepublicvoiddelete(Serializableid){getHibernateTemplate().delete(findObjectById(id));}@OverridepublicTfindObjectById(Serializableid){returngetHibernateTemplate().get(clazz,id);}@OverridepublicList<T>findObjects(){Queryquery=getSession().createQuery("FROM"+clazz.getSimpleName());returnquery.list();}

    }


    <preclass="brush:java;toolbar:true;auto-links:false;">UserDaoImplpublicclassUserDaoImplextendsBaseDaoImpl<User>implementsBaseDao<User>{}





    你昏头了吧。。。。

    很明显,userDAOImpl应该实现userDAO接口,而不是BaseDao<User>接口。

    你可以 userDAOextends BaseDao<User>,然后 userDAOImpl extendsBaseDAOImplimplementsuserDAO

    谢谢您,已经成功解决,看来时我写代码的时候太过疏忽,自己在xml里面找了半天也没解决,大神请手下本小白的膝盖。好的,您说的方法我稍后试试,谢谢您的解决方案佟刚的还是?

    2020-06-09 12:39:49
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多