spring mvc 3- context:property-placeholder不受约束

Dee*_*rur 3 spring-mvc

我正在使用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"/>
Run Code Online (Sandbox Code Playgroud)

应用程序启动时,我收到以下错误:

违规资源:ServletContext资源[/WB-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"未绑定.

我究竟做错了什么?

Jos*_*osh 21

您还没有定义"上下文"是什么.

你需要添加 xmlns:context="http://www.springframework.org/schema/context"