搭建springmvc环境遇到的问题

原创 2016年08月30日 16:14:02

问题:

严重: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:Could not autowire field: private cn.zn.service.UserService cn.zn.controller.UsersController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:No matching bean of type [cn.zn.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
 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)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.zn.service.UserServicecn.zn.controller.UsersController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [cn.zn.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    ... 36 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [cn.zn.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 38 more


看见别人博客写的问题可能出处与解决方法有三处:

1、UserServiceImp实现类上必须有注解@Service

2、在UserController类里面注入service,一定要注入接口类,而不是实现类

  改:

@Autowired
    private UserServiceImp   userServiceImp;

为:

  @Autowired
    private  UserService  userService;

3、在UserDaoImp实现类上加上@Repository注解


我发现我的代码里不存在这些问题,依然报错,那就看一下我的配置文件了,最后发现问题出在xml配置文件里

下面这段代码不仅仅扫描@Controller注解的Bean,而且还扫描了@Component的子注解@Service、@Reposity

<context:component-scan base-package="cn.zn" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>


use-default-filters="false"去掉重启一下就可以了

<context:component-scan base-package="cn.zn" >
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

use-default-filters默认为true。如果不需要默认的,则use-default-filters=“false”,根据需要,我这里用默认的就可以。

希望也能够帮到你


使用springmvc遇到的问题

1.在使用spring管理bean时重要的一点是提供getset方法还有无参构造函数。 最近在使用springmvc中的@requestBody时没有注意到这一点,导致参数一直获取不到,也不报错,最后...
  • u014788227
  • u014788227
  • 2016年04月16日 21:23
  • 563

Spring Mvc开发遇到的问题汇总

eclipse  Version: Luna Service Release 2 (4.4.2) Build id: 20150219-0600 jdk 1.8 tomcate8 问题一:T...
  • wei_chong_chong
  • wei_chong_chong
  • 2016年11月15日 21:21
  • 399

springmvc异常StandardWrapper.Throwable

严重: StandardWrapper.Throwable org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:...
  • lujinmin
  • lujinmin
  • 2017年10月22日 23:23
  • 152

spring线程池ThreadPoolExecutor配置并且得到任务执行的结果

spring线程池ThreadPoolExecutor配置并且得到任务执行的结果,代码下载地址:http://www.zuidaima.com/share/1724478138158080.htm...
  • yaerfeng
  • yaerfeng
  • 2014年04月05日 21:16
  • 30110

说说tomcat启动的错误: StandardWrapper.Throwable

tomcat版本: 5.5.26这是我用书上的代码增加了一个项目网站,但每次启动tomcat时都会有这种提示,后来用eclipse也是如此.其错误的代码如下:2007-11-9 23:05:13 or...
  • lhxiong
  • lhxiong
  • 2008年05月16日 10:42
  • 9268

搭建springmvc环境遇到的问题

解决springmvc环境搭建遇到的问题 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationExc...
  • shandongzhouna
  • shandongzhouna
  • 2016年08月30日 16:14
  • 601

spring+springmvc+mybabits框架论坛开发中遇到的问题

autowired 注入失败 报错: Caused by: org.springframework.beans.factory.BeanCreationException: Coul...
  • qq_21149391
  • qq_21149391
  • 2017年08月14日 10:08
  • 174

学习springmvc时遇到的问题

① The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 完整错误信息: T...
  • yuwenlanleng
  • yuwenlanleng
  • 2017年01月14日 11:23
  • 492

严重: StandardWrapper.Throwable

当我们再启动的时候发现:  严重: StandardWrapper.Throwable;这样的异常; 这是由于依赖的jar包出现少包或者冲突导致的, commons的1.0已经用不了;基本...
  • qq_36763348
  • qq_36763348
  • 2017年11月09日 13:53
  • 212

严重: StandardWrapper.Throwable

64位系统里,安装64位/32位JDK,32位apache-tomcat-6.0.29,项目里加载32位OS里编译的DLL,启动项目,log里报错:严重: StandardWrapper.Throwa...
  • dingherry
  • dingherry
  • 2011年08月31日 11:11
  • 4645
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:搭建springmvc环境遇到的问题
举报原因:
原因补充:

(最多只允许输入30个字)