1.加载.properties文件中的配置参数加载到PropertiesFactoryBean容器中

<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">//本地资源 读取方式,用流读取资源进行加载。
<list>
<value>classpath:config.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>

如此,两个properties 的属性变被放入了Spring 的PropertiesFactoryBean中

在此,有一点需要注意,如果在xml中需要用到刚刚配置的属性,我们会去用${“key”}方式去取,此时需要配置“占位符“,

<!--在xml使用properties文件中的的配置数据时,需要用到PropertyPlaceholderConfigurer做占位符-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<ref bean="configProperties"/>
</property>
</bean>

PropertyPlaceholderConfigurer会把配置的properties解析并存放为java标准的properties,此时在xml中我们可以通过${"key"}去取。

2.

<bean name="DatabaseConfigrationFactoryBean" class="com.shopManager.config.DatabaseConfigrationFactoryBean">
<constructor-arg ref="DatabaseConfiguration"/>
</bean> <bean name="DatabaseConfiguration" class="org.apache.commons.configuration.DatabaseConfiguration">
</bean>
/**
* Build a configuration from a table containing multiple configurations.
* No commits are performed by the new configuration instance.
*
* @param datasource the datasource to connect to the database
* @param table the name of the table containing the configurations
* @param nameColumn the column containing the name of the configuration
* @param keyColumn the column containing the keys of the configuration
* @param valueColumn the column containing the values of the configuration
* @param name the name of the configuration
*/
public DatabaseConfiguration(DataSource datasource, String table, String nameColumn,
String keyColumn, String valueColumn, String name)
{
this(datasource, table, nameColumn, keyColumn, valueColumn, name, false);
}

从它的这个构造中我们可以发现需要传入的参数,数据源、表名、名称配置环境的名称、属性名、属性值,配置名称。(可以根据自己需要进行配置)

spring 配置参数从配置文件中加载到PropertiesFactoryBean 和配置参数从数据库加载到PropertiesFactoryBean 的实现,及项目中的相关应用的更多相关文章

  1. C# 动态创建SQL数据库(二) 在.net core web项目中生成二维码 后台Post/Get 请求接口 方式 WebForm 页面ajax 请求后台页面 方法 实现输入框小数多 自动进位展示,编辑时实际值不变 快速掌握Gif动态图实现代码 C#处理和对接HTTP接口请求

    C# 动态创建SQL数据库(二) 使用Entity Framework  创建数据库与表 前面文章有说到使用SQL语句动态创建数据库与数据表,这次直接使用Entriy Framwork 的ORM对象关 ...

  2. NoSql非关系型数据库之MongoDB应用(三):MongoDB在项目中的初步应用

    业精于勤,荒于嬉:行成于思,毁于随. 我们可以结合相关的IDE做一个简单的增删改查了,实现MongoDB在项目中的初步应用. 前提是安装了MongoDB服务和MongoDB可视化工具,没有安装的可以点 ...

  3. Java Web项目中连接Access数据库的配置方法

    本文是对前几天的"JDBC连接Access数据库的几种方式"这篇的升级.因为在做一些小项目的时候遇到的问题,因此才决定写这篇博客的.昨天已经将博客公布了.可是后来经过一些验证有点问 ...

  4. 十、VueJs 填坑日记之在项目中使用Amaze UI

    上一篇博文,我们把jQuery集成到了项目中,今天我们来集成Amaze ui(妹子UI).先来介绍一下妹子UI.Amaze UI 含近 20 个 CSS 组件.20 余 JS 组件,更有多个包含不同主 ...

  5. 浅谈 Axios 在 Vue 项目中的使用

    介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 特性 它主要有如下特性: 浏览器端发起XMLHttpRequests请求 Node端发起http ...

  6. JAVA 项目中使用 H2 数据库

    为什么要使用H2数据库 H2数据库是可以嵌入到JAVA项目中的,因为只需要导入一个jar包即可,所以非常的方便. 项目中导入H2 将H2的jar包放到classpath里即可,我是用的maven,ma ...

  7. 31_java之项目中的数据库操作

    01项目训练目标 * A: 项目训练目标 * a: 项目目标 * 综合运用前面所学习的知识点 * 熟练View层.Service层.Dao层之间的方法相互调用操作. * 熟练dbutils操作数据库表 ...

  8. SLF4J 和 Logback 在 Maven 项目中的使用方法

    原文:http://blog.csdn.net/llmmll08/article/details/70217120 本文介绍 SLF4J 和 Logback 在 Maven 项目中的用法,包括日志框架 ...

  9. 在WEB项目中调用QQ通讯组件打开QQ聊天界面

    在很多WEB项目中,需要提供在线服务的功能,加上自己的联系方式,例如:QQ,不用添加QQ好友也可以交谈,那这到底是怎么实现的呢? 对于这个功能,需要提到一个组件,即“QQ通讯组件”.QQ通讯组件是一种 ...

  10. 记录第一次在egret项目中使用Puremvc

    这几天跟着另一个前端在做一个小游戏,使用的是egret引擎和puremvc框架,这对于我来说还是个比较大的突破吧,特此记录下. 因为在此项目中真是的用到了mvc及面向对象编程,值得学习 记录第一次在e ...

随机推荐

  1. python pip 出现locations that require TLS/SSL异常处理方法

    python pip 出现locations that require TLS/SSL异常处理方法 转载 郑才华 发布于2018-03-24 21:41:16 阅读数 51844 收藏 展开 最近在r ...

  2. GLSLPROGRAM METALPROGRAM unity

    https://docs.unity3d.com/Manual/SL-GLSLShaderPrograms.html unity里面可以直接写原生的shader 用相应的宏包起来 CGPROGRAM ...

  3. TBDR下msaa 在metal vulkan和ogles的解决方案

    https://developer.arm.com/solutions/graphics/developer-guides/understanding-render-passes/multi-samp ...

  4. C# ado.net DataSet使用(五)

    一.填充dataset class Program { private static string constr = "server=.;database=northwnd;integrat ...

  5. java中volatile关键字的含义(转载)

    在java线程并发处理中,有一个关键字volatile的使用目前存在很大的混淆,以为使用这个关键字,在进行多线程并发处理的时候就可以万事大吉. Java语言是支持多线程的,为了解决线程并发的问题,在语 ...

  6. shell爬取斗图网

    #!/bin/bash read -p "请输入要爬取的页面数(默认为10):" page_num page_num=${page_num:-} echo $page_num re ...

  7. 百度ueditor实现word图片自动转存

    官网地址http://ueditor.baidu.com Git 地址 https://github.com/fex-team/ueditor 参考博客地址 http://blog.ncmem.com ...

  8. ASP.NET大文件分片上传

    文件夹数据库处理逻辑 public class DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject() ...

  9. Codevs 2505 上学路线 (组合数学)

    2505 上学路线 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 因为是学生,所以显然小A每天都要上学.小A所在的城市的道路构 ...

  10. Ubuntu 出现 Invalid operation update 或 Invalid operation upgrade的解决办法

    输入 sudo apt update && sudo apt full-upgrade