• JavaEE笔记(十一)


    Spring beans使用参数占位符(JDBC配置读取示例)

    beans.xml配置文件

    <?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.xsd">
    
          <context:property-placeholder location="db.properties"/>     
    
            <!-- 占位符 得配置方式-->
            <bean id="dbUtil" class="com.my.util.DBUtil">
            <property name="driverName"  value="${driverName}"/>
            <property name="url" value="${url}"/>
            <property name="username" value="${username}" />
            <property name="pwd" value="${pwd}"/>
            </bean>
     
      <!-- 注册propertyPlaceholderConfigurer对象->
      <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="locations">
          <list>
            <value>db.properties</value>
          </list>
        </property>
      </bean> 
       -->
     
     
    </beans>           

    db.properties 配置文件

    driverName=com.mysql.jdbc.Driver
    url=jdbc:mysql://127.0.0.1:3306/jg29
    username=root
    pwd=root

    (# 降低耦合度,符合开闭原则【对拓展开、对修改源码闭】)

    我不作恶

    但有权拒绝为善

    我不赞同

    但是我捍卫你不为善的权力

  • 相关阅读:
    基于微软平台IIS/ASP.NET开发的大型网站
    谈谈用ASP.NET开发的大型网站有哪些架构方式(成本)
    微软Expression Blend基础教程系列
    Silverlight类库介绍FJCore
    Blend基础数据绑定
    Windows Embedded 版 Silverlight “Cashmere”
    Blend基础动画
    Blend基础控件与用户控件
    Silverlight 4 新特性归纳整理
    SQL经典短小代码收集
  • 原文地址:https://www.cnblogs.com/HackerBlog/p/6143236.html
Copyright © 2020-2023  润新知