Spring_8_使用外部属性文件
来源:互联网 发布:用java代码表白 编辑:程序博客网 时间:2024/05/22 19:12
使用如下命令引用外部的属性文件
<context:property-placeholder location="classpath:database.properties"/>
然后使用${xxxx}的方式引用属性文件中的值
- bean-properties.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" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><context:property-placeholder location="classpath:database.properties"/><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}" /> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}" /></bean></beans>
- TestSpring
package com.hgh.spring.scope;import java.sql.SQLException;import javax.sql.DataSource;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestSpring { public static void main(String[] args) throws SQLException { ApplicationContext ac = new ClassPathXmlApplicationContext("bean-properties.xml"); DataSource dataSource = (DataSource) ac.getBean("dataSource"); System.out.println(dataSource.getConnection()); }}
0 0
- Spring_8_使用外部属性文件
- spring 使用外部属性文件
- 10011---使用外部属性文件
- 4、使用外部属性文件
- Spring 使用外部属性文件
- Spring使用外部属性文件
- Spring使用外部属性文件
- spring-使用外部属性文件
- Spring 使用外部属性文件
- spring使用外部属性文件
- spring使用外部属性文件
- spring ioc之使用外部属性文件
- Spring IOC使用外部属性文件
- Spring 使用外部属性文件(连接数据库)
- Spring-Bean配置-使用外部属性文件
- Spring 中如何使用外部属性文件
- (八)spring_使用外部属性文件
- Spring-7:使用外部属性文件
- HTTP Status 500 - Servlet.init() for servlet springmvc threw exception
- mysql 列转行,合并字段
- 基于谷歌draco项目的测试---三维模型数据压缩方案
- CentOS生成自签名证书配置Apache https
- 类型别名typedef与#define
- Spring_8_使用外部属性文件
- eclipse快捷键 包括查找类、方法、变量
- HDU 1069 Monkey and Banana
- JAVAEE 面试题摘要
- 最好用的 20 款数据可视化工具
- C++重载++ 如何区分“++”重载的前置与后置
- Java虚拟机垃圾回收(四) 总结:内存分配与回收策略 方法区垃圾回收 以及 JVM垃圾回收的调优方法
- ubuntu CH341 Serial actually without securecrt
- Apache Shiro