**
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無語,報錯,還運行沒問題,