我正在使用spring 3.0.5并尝试通过context元素读取配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:property-placeholder location="classpath:db_config.properties"/>
当应用程序启动时,我收到以下错误:
攻击资源:ServletContext资源[/WEB-INF/spring/applicationContext.xml];嵌套异常是org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自ServletContext资源[/WEB-INF/spring/db-config.xml]的XML文档中的第20行无效;嵌套异常是org.xml.sax.SAXParseException:元素“context:property-placeholder”的前缀“context”未绑定。
我做错了什么?
答案 0 :(得分:19)
您尚未定义“上下文”是什么。
您需要添加xmlns:context="http://www.springframework.org/schema/context"
答案 1 :(得分:0)
在applicationContext.xml中更改您的bean配置
<?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-3.0.xsd">
</beans>