加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

通配符的匹配很全面, 但无法找到元素 'context:component-sc

发布时间:2020-12-16 23:05:10 所属栏目:百科 来源:网络整理
导读:一开始的context.xml中的配置文件如下: ? 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/s

一开始的context.xml中的配置文件如下:

<?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">
    <context:component-scan base-package="com.alice.*"/>
    <context:property-placeholder location="classpath:config.properties"/>
    <import resource="classpath*:application-cache.xml" />
    <import resource="classpath*:application-spring.xml" />
    <import resource="classpath*:application-mybatis.xml"/>
</beans>

结果运行的时候报以下的错误

通配符的匹配很全面,但无法找到元素 ‘context:component-scan‘ 的声明

经各种百度,错误原因在于beans中的元素不全面,至少缺少以下两个

http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd

补充完整后,运行即可。

<?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="com.alice.*"/>
    <context:property-placeholder location="classpath:config.properties"/>
    <import resource="classpath*:application-cache.xml" />
    <import resource="classpath*:application-spring.xml" />
    <import resource="classpath*:application-mybatis.xml"/>
</beans>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读