标签:spring
beans-properties.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"<context:property-placeholder location="classpath:db.properties"/>
</beans>
外部文件为:db.properties
jdbc.user=root
jdbc.password=1230
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql:///test
测试类:
package com.spring.properties;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class main {
public static void main(String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans-properties.xml");
DataSource source = (DataSource) ctx.getBean("dataS");
System.out.println(source.getConnection());
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:spring
原文地址:http://blog.csdn.net/u010220089/article/details/47984453