zoukankan      html  css  js  c++  java
  • spring 读取properties的两种方法

    一:直接使用context命名空间

    <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"
    xmlns:websocket="http://www.springframework.org/schema/websocket"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/websocket
    http://www.springframework.org/schema/websocket/spring-websocket.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder location="classpath:log4j.properties" />  

    二:在配置文件中配置PropertyPlaceholderConfigurer

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations" value="classpath:jdbc.properties" />
    </bean>

    实例:

    <!-- property-placeholder是一个属性遍历器,定位一个属性文件,属性文件存放的是jdbc一些连接数据 -->
        <context:property-placeholder location="classpath:jdbc.properties" />
        
        <!-- 配置数据源 -->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="${driverClassName}" />
            <property name="url" value="${url}" />
            <property name="username" value="${username}" />
            <property name="password" value="${password}" />
            <property name="initialSize" value="${initialSize}" />
            <property name="maxActive" value="${maxActive}" />
            <property name="maxIdle" value="${maxIdle}" />
            <property name="minIdle" value="${minIdle}" />
        </bean>
  • 相关阅读:
    *****Exercise 4.1 Generate a multiplication table
    Exercise 3.4 A calculator that allows multiple calculations
    Exercise 3.3 Calculate a discounted price
    Exercise 3.2 Display a date
    理解Java异常处理机制
    eclipse远程Debug配置
    [转]java代码性能优化总结
    [转]A星寻路算法
    JVM参数配置
    Gradle笔记(1) 安装
  • 原文地址:https://www.cnblogs.com/beyang/p/6074115.html
Copyright © 2011-2022 走看看