could not Autowired

最近在配置SSM中遇到这个问题

找了好多资料都没查到,最后才发现。web.xml中没有加入springmvc.xml,导致他不能扫描@Controller注释的类
仔细检查web.xml一定要加入spring.xml(applicationContext.xml)和springmvc.xml
加载初始化spring.xml
<!-- 声明应用范围(整个WEB项目)内的上下文初始化参数 -->
  <!-- 初始化spring容器 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
加载初始化springmvc.xml
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 初屎化springmvc -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

如何在业务逻辑层(Service)中出现could not Autowired

<!-- -扫描映射器并让它们自动装配-->
    <!-- 这个配置如何出现could not Autowired No beans of 'EmployeeMapper' type found
         那就用下面注释的配置 -->
    <mybatis:scan base-package="com.atguigu.mybatis.dao"/>
    <!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.atguigu.mybatis.dao"/>
    </bean>-->
这样就能解决问题了,而不是在什么File ——> Settings ——> Editor ——> Inspections更改spring检查的错误级别。掩耳盗铃
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值