Spring4.2.4版本配置context:component-scan标签报错

**

Spring4.2.4版本配置context:component-scan标签报错

**

首先,附正确的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-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.xsd">
	
	<!-- xsi:schemaLocation配置中,一定要加入版本号 -->
	
	<!-- 开启注解扫描 
	(1)到包里面扫描类,方法,属性上面是否有注解
	-->
	<context:component-scan base-package = "cn.itcast"></context:component-scan>
	
	<!-- 只会扫描属性上的注解 -->
	<context:annotation-config></context:annotation-config>
	
</beans>

下面来看看错误的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
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
	
	<!-- xsi:schemaLocation配置中,一定要加入版本号 -->
	
	<!-- 开启注解扫描 
	(1)到包里面扫描类,方法,属性上面是否有注解
	-->
	<context:component-scan base-package = "cn.itcast"></context:component-scan>
	
	<!-- 只会扫描属性上的注解 -->
	<context:annotation-config></context:annotation-config>
	
</beans>

同时我们也看一下具体的错误
在这里插入图片描述
正确的代码跟错误的代码区别在哪里?
在这里插入图片描述
配置xml文件时,需要把Spring对应的版本号写进去,
添加进去就ok了

还有,eclipse这个IDE无语,报错,还运行没问题,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章