如何处理cvc-complex-type.4:属性'base-package'必须出现在元素'context:component-scan'上

时间:2013-08-08 19:52:29

标签: spring-mvc

我是Spring的新手,我的spring配置文件抛出异常

<?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:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:beans="http://www.springframework.org/schema/beans"
 xmlns:context="http://www.springframework.org/schema/context" 
  xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
 http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 <property name="prefix" value="/WEB-INF/"/> 
 <property name="suffix" value=".jsp"/> 
  </bean>
   <context:component-scan></context:component-scan>
   </beans>

它给cvc-complex-type.4:属性'base-package'必须出现在元素'context:component-scan'上。

1 个答案:

答案 0 :(得分:2)

只需阅读错误信息,您需要像这样添加组件扫描

<context:component-scan base-package="com.xxx.service"/>

告诉spring扫描包并添加所有bean注释 弹簧上下文@Component,@ Service,@ Controller等等;

如果您在此基础包中向上面添加注释,则可以在spring上下文中使用此bean。