spring创建bean失败原因及解决办法

首先看一下报错信息



首先一看报错信息,bean创建失败,创建bean的配置就只有spring.xml中才有配置,看着这种错,果断打开spring.xml;



由于有些地方不方便透漏,改成了**,可以自行脑补


错误的地方可能存在与1:

   包扫描没有配置

   <!-- 自动包扫秒 -->
   <context:component-scan base-package="com.**">
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
   </context:component-scan>

2: 在web.xml里没有加载spring容器,这个就需要回到web.xml查看是否配置spring 的监听器
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring.xml</param-value>
  </context-param>
  
  <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
  </listener>

3:注意单词大小写,可能是大小写误差,特别是引用的:::
<property name="dataSource" ref="dataSource"></property>
4:jar包版本引起的冲突,这个我需要总结一下,,

版权声明:本文为weixin_41868360原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。