代码改变世界

配置spring文件时候出现的小问题

2015-04-01 17:58  Cter12138  阅读(204)  评论(0编辑  收藏  举报

Spring中的配置bean有两种方式,今天做毕业设计的时候想使用注解的方式(简单,方便)自动扫描装配bean

大概是这样的语句

<!-- 自动扫描与装配bean -->

<context:component-scan base-package="cn.hlg.oa"></context:component-scan>

但是发现会出现一个错误

The prefix "context" for element "context:component-scan" is not bound.//大概意思就是这个东西无效,系统找不到。

对于上面这个错误的解决办法是在<beans >中加上一句

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

这个还是很好找到的,可是下一步,我足足试了两个多小时,就是这个错误解决之后,小红叉并没有消失,错误变成了

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.

大概就是这个表情没被引进去,解决办法是在xsi:schemaLocation里面加上两句

http://www.springframework.org/schema/context

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

至此这个问题总算是解决了。