[关闭]
@Cesar 2016-01-05T01:31:37.000000Z 字数 1072 阅读 1707

使用Spring注解进行注入时可能遇到的错误

Spring Java 学习

输入时报错

The prefix "context" for element "context:annotation-config" is not bound.

该错误原因是没有引入context的空间,只需要在

< beans xmlns="http://www.springframework.org/schema/beans"

后面加上一行变为:

< beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"

就可以了

关于spring”通配符的匹配很全面, 但无法找到元素

在xsi后面加上两个地址:

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

就可以了

最后将总的配置文件发布一下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-3.1.xsd"
  9. >
  10. <context:annotation-config></context:annotation-config><!--这个代表着允许使用注解进行装配-->
  11. </beans>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注