初学SpringMvc遇到的困难

在用spring写一个简单的查询功能的时候,测试查询能够通过,但是在tomcat服务器中始终报错
javax.servlet.ServletException: Servlet[springmvc]的Servlet.init()引发异常
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lmj.service.ItemService com.lmj.controller.ItemController.itemService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lmj.service.ItemService] 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)}

org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lmj.service.ItemService com.lmj.controller.ItemController.itemService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lmj.service.ItemService] 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)}

一直在报错,我百度了很多的解决办法,很多都说是bean没加载这个ItemService,自动注入有问题,我改了很多次,还是在出这个错,实在自己找不到这个错误在哪里,重新创建一个maven项目,将代码直接copy进去,发现还是这个错误,然而测试类能够通过,于是开始查找xml文件的问题,从appliction.xml开始查找,发现代码没有问题,启动tomcat能够加载index页面,我直接进入web.xml查找问题,发现了监听器的问题

这个是报错的web.xml:

 修改之后的web.xml:

 原来自己监听器写错了,修改之后成功运行.

总结:写代码的时候一定要细心,一个小错误就能够引发很多的错误,学习要长久且细心的学下去

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值