您的位置:首页 > 运维架构

通配符的匹配很全面, 但无法找到元素 'context:property-placeholder'

2018-01-26 22:48 267 查看
这是我在学习spring的时候遇到的一个错误,下面我给大家介绍一种解决方案:

其实主要是我们在引入命名空间时没有正确引入它的DTD解析文件,当然你必须在把Spring相应的包导入正确的情况下。

解决方案就是如下:

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

同时在xsi:schemaLocation这个字符串中添加context相关的解析文件
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd。
其他的如util命名空间导入方式一样,只是把context换成相应util就可以了。

最终的代码如下:

<?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-4.2.xsd">

<!--导入属性文件-->
<context:property-placeholder location="classpath:db.properties"/>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
</bean>
</beans>

本人小白,希望对大家的学习有所帮助
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐