关于spring配置文件的context:component-scan不能被识别问题解决方法

 错误代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<context:component-scan base-package="package01"></context:component-scan>

原因是:没有引入context约束:

 xmlns:context="http://www.springframework.org/schema/context" 

整体代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

<context:component-scan base-package="package01"></context:component-scan>

添加上上面的即可解决;

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页