ssm的web项目遇到Could not autowire.No beans of ‘xxx‘ type found解决方法排查

本文介绍了如何正确地配置Spring MVC与Spring容器以确保Service接口实现类被正确识别和服务注入。主要内容包括@Service注解的使用、spring容器与SpringMVC容器的扫描配置,以及web.xml中的相关配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Service接口实现类要加上正确的@Service注解

import org.springframework.stereotype.Service;

在这里插入图片描述

2.注意spring容器的扫描和SpringMVC容器的扫描不要错

例子
spring

    <!-- 配置扫描路径 -->
    <context:component-scan base-package="com.biao.*" use-default-filters="true">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

SpringMVC

    <!-- 扫描路径的配置 -->
    <context:component-scan base-package="com.biao" use-default-filters="false">
    <context:include-filter
            type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

3.注意要在web.xml的配置文件中导入spring和mybatis的配置文件

我的项目配置文件名都是以 applicationContext- 开头的,所以我这里用 applicationContext-*

在这里插入图片描述

    <!--配置Spring,初始化spring容器-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/applicationContext-*.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值