【工具】Eclipse 使用svn插件检出maven项目,启动服务时提示依赖注入失败

Eclipse 使用svn插件检出maven项目,启动tomcat服务器时提示依赖注入失败

控制台错误信息

No qualifying bean of type [xxx.xxx] 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)}

解决步骤
1.eclipse 检出后 maven 项目后,右键项目名,在右键菜单中点击configure 选择 convert to maven project
2.右键项目名,点击Build Path 选择 Configure Build Path...
3.在Java Build PathSource面板中,点击右侧的Add Folder...
4.在Source Folder Selection弹窗中勾选resource文件夹前的复选框
5.重新编译项目、部署到tomcat中,启动tomcat,项目可以正常访问
这里写图片描述
这里写图片描述

原因分析
先看下web.xml中关于spring的配置

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:applicationContext.xml
    </param-value>
</context-param>

<servlet>
    <servlet-name>springServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

ContextLoaderListener加载的配置文件是类路径(即classes)下的applicationContext.xml
DispatcherServlet加载的配置文件是WEB-INF下的spring-mvc.xml
这里写图片描述
前面项目启动的时候报错,是因为resources文件在编译、部署的时候并没有被加载到/WEB-INF/classes路径下,导致ContextLoaderListener并没有成功加载applicationContext.xml,以至于依赖的bean未生成,而无法注入

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值