首页 > 编程语言 > 详细

spring中<context:property-placeholder>的作用

时间:2017-01-09 18:07:42      阅读:396      评论:0      收藏:0      [点我收藏+]

context:property-placeholder方便了我们数据库的配置。

spring 3.0 后提供了 注解配置引入,<context:property-placeholder/>,方便。但是往往第一次使用时会遇到此属性配置进applicationContext.xml文件中,会出现红叉:
“The prefix "context" for element "context:property-placeholder" is not bound. ”

只需要在文件头中引入:xmlns:context="http://www.springframework.org/schema/context" 即可。
举例如下:
<?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-3.0.xsd">

   <context:property-placeholder location="classpath:jdbc.properties"/>
   <bean id="dataSource"  class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
   </bean>
</beans>

jdbc.properties:
#jdbc配置
jdbc.driverClassName = Oracle.jdbc.driver.OracleDriver
jdbc.url = jdbc:oracle:thin:@//localhost:1521/orcl
jdbc.username = scotter
jdbc.password = 123

spring中<context:property-placeholder>的作用

原文:http://www.cnblogs.com/yuwei1/p/6266029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!