-
Servlet[DispatcherServlet]的Servlet.init()引发异常
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountController': Unsatisfied dependency expressed through field 'accountService'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'accountServiceImpl' is expected to be of type 'com.jancy.service.impl.AccountServiceImpl' but was actually of type 'com.sun.proxy.$Proxy26' org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:598) org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1377) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:848) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:865) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:696) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:662) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:710) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:587) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:526) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:169) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:748)
关键是第一句话: >org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountController': Unsatisfied dependency expressed through field 'accountService'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'accountServiceImpl' is expected to be of type 'com.jancy.service.impl.AccountServiceImpl' but was actually of type 'com.sun.proxy.$Proxy26'
这句异常的意思是:Controller类中的accountService类型的自动自动注入失败,因为AccountServiceImpl类的类型注入失败。
原因:自动注入@Autowired注入的对象必须是接口,因此在Controller类应该注入AccountServiceImpl类所继承的接口类,本例中为IAccountService。
注意:@Compoment注解及其三个子注解注解的对象是class类 -
springmvc框架自动注入对象,需要jsp页面name属性与实体类名称一致,否则null。或者添加@RequestParam注解
-
java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener
解决:转载他人的一片文章:
https://www.jianshu.com/p/18d068f47b09
SSM整合时遇到的问题
最新推荐文章于 2022-03-26 16:32:52 发布