spring 注入失败

J2EE 码拜 9年前 (2016-05-21) 1377次浏览
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name “org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0”: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name “testController”: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name “commentService” defined in file [D:\soft\apache-tomcat-7.0.53\wtpwebapps\springmvcsush\WEB-INF\classes\cn\itcast\springmvc\service\CommentServiceImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [cn.itcast.springmvc.dao.CommentDao]: : Error creating bean with name “commentDao” defined in file [D:\soft\apache-tomcat-7.0.53\wtpwebapps\springmvcsush\WEB-INF\classes\cn\itcast\springmvc\dao\CommentDaoImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [cn.itcast.springmvc.dao.CommentDaoImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: cn.itcast.springmvc.dao.CommentDaoImpl.<init>(); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name “commentDao” defined in file [D:\soft\apache-tomcat-7.0.53\wtpwebapps\springmvcsush\WEB-INF\classes\cn\itcast\springmvc\dao\CommentDaoImpl.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [cn.itcast.springmvc.dao.CommentDaoImpl]: No default constructor found; nested exception is java.lang.NoSuchMethodException: cn.itcast.springmvc.dao.CommentDaoImpl.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
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.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
下面是配置
<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:mvc=”http://www.springframework.org/schema/mvc”
xmlns:context=”http://www.springframework.org/schema/context”
xmlns:aop=”http://www.springframework.org/schema/aop”
xmlns:tx=”http://www.springframework.org/schema/tx”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd “>
<!– mvc的注解驱动 –>
<mvc:annotation-driven/>
<!– 一旦有扫描器的定义mvc:annotation-driven不需要,扫描器已经有了注解驱动的功能 –>
<context:component-scan base-package=”cn.itcast.springmvc”/>
<bean class=”org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter” />
<!– 前缀+ viewName +后缀 –>
<bean class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<!– webroot到某一指定的文件夹的路径 –>
<property name=”prefix” value=”/WEB-INF/jsp/”></property>
<!– 视图名称的后缀 –>
<property name=”suffix” value=”.jsp”></property>
</bean>
<!– id=”multipartResolver”必须是multipartResolver –>
<!– <bean id=”multipartResolver” class=”org.springframework.web.multipart.commons.CommonsMultipartResolver”>
maxUploadSize:文件上传的最大值以byte为单位
<property name=”maxUploadSize” value=”1024000″></property>
</bean> –>
<mvc:interceptors>
<mvc:interceptor>
<!–  某一模块的拦截:/myPath/**, 拦截全部的请求/**
–> <mvc:mapping path=”/test/**”/>
<bean class=”cn.itcast.springmvc.interceptor.MyIntercepor”></bean>
</mvc:interceptor>
</mvc:interceptors>
</beans>
解决方案

20

tomcat下编译的文件tomcat下webapps下你的项目名称命名的文件夹删了,重新编译。原因是里面放的是以前的编译后的文件,所以
Error creating bean with name “commentDao” defined in file [D:\soft\apache-tomcat-7.0.53\wtpwebapps\springmvcsush\WEB-INF\classes\cn\itcast\springmvc\dao\CommentDaoImpl.class  找不到这个,创建失败

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring 注入失败
喜欢 (0)
[1034331897@qq.com]
分享 (0)