package com.zsw.config;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class Config {
public static void main(String[] args) {
XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("src/com/zsw/config/conf.xml"));
// 如果要在BeanFactory中使用,bean factory post-processor必须手动运行:
PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
cfg.setLocation(new FileSystemResource("src/com/zsw/config/jdbc.properties"));
cfg.postProcessBeanFactory(factory);
DriverManagerDataSource dataSource = (DriverManagerDataSource) factory.getBean("dataSource");
// System.out.println(dataSource.getDriverClassName());
System.out.println(dataSource.getUsername());
// 注意,ApplicationContext能够自动辨认和应用在其上部署的实现了BeanFactoryPostProcessor的bean。这就意味着,当使用ApplicationContext的时候应用PropertyPlaceholderConfigurer会非常的方便。由于这个原因,建议想要使用这个或者其他bean
// factory postprocessor的用户使用ApplicationContext代替BeanFactroy。
ApplicationContext context = new ClassPathXmlApplicationContext("com/zsw/config/conf.xml");
DriverManagerDataSource dataSource2 = (DriverManagerDataSource) context.getBean("dataSource");
System.out.println(dataSource2.getUsername());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Spring属性占位符PropertyPlaceholderConfigurer的使用
共19个文件
xml:4个
jar:3个
properties:2个
3星 · 超过75%的资源 需积分: 49 20 下载量 110 浏览量
2011-08-07
04:12:06
上传
评论
收藏 2.93MB ZIP 举报
温馨提示
Spring属性占位符PropertyPlaceholderConfigurer的使用,自己写的一个demo
资源推荐
资源详情
资源评论
收起资源包目录
Spring_ppc.zip (19个子文件)
Spring_ppc
.project 1KB
.settings
.jsdtscope 454B
org.eclipse.wst.common.component 460B
org.eclipse.jdt.core.prefs 330B
org.eclipse.wst.common.project.facet.core.xml 229B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
com
zsw
config
Config.java 2KB
conf.xml 1KB
jdbc.properties 421B
build
classes
com
zsw
config
conf.xml 1KB
jdbc.properties 421B
Config.class 2KB
WebContent
WEB-INF
web.xml 640B
lib
spring-2.5.6.jar 2.81MB
commons-logging-api-1.1.jar 44KB
mysql-connector-java-3.1.13-bin.jar 446KB
META-INF
MANIFEST.MF 39B
.classpath 593B
共 19 条
- 1
资源评论
- c_79_68_692012-10-09内容是一个web程序,但是不好用
sz_bdqn
- 粉丝: 398
- 资源: 129
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功