博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring 注入 Properties
阅读量:4049 次
发布时间:2019-05-25

本文共 1167 字,大约阅读时间需要 3 分钟。

– Start


package shangbo.spring.core.example21;import java.util.Properties;public class DataService {	private Properties dbconfig;	public void setDbconfig(Properties dbconfig) {		this.dbconfig = dbconfig;	}	public String toString() {		return dbconfig.toString();	}}
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/mydb
package shangbo.spring.core.example21;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class App {	public static void main(String[] args) {		// 实例化 Spring IoC 容器		ApplicationContext context = new ClassPathXmlApplicationContext("example.xml", DataService.class);		// 从容器中获得 Service 对象		DataService p = context.getBean(DataService.class);		// 使用对象		System.out.println(p);	}}

我们也可以通过如下方式定义Properties

jdbc.driver.className=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mydb

– 声 明:转载请注明出处
– Last Updated on 2017-06-17
– Written by ShangBo on 2017-05-22
– End

你可能感兴趣的文章
春寒料峭,原来春天这样走近
查看>>
电脑坏了--关于联想笔记本声卡驱动
查看>>
C#中枚举类型在switch语句中值对照问题
查看>>
GridView中根据特殊标记设置不可编辑
查看>>
PowerDesinger中生成数据库时将域的内容转化为实际的字段
查看>>
通过模板将GridView导出为Excel
查看>>
迭代开发过程及一些原则
查看>>
Windows IIS服务器CA认证安装
查看>>
Asp.net 中Excel通过模板导出中发布问题
查看>>
64位机器配置CA认证一些小问题
查看>>
SVN自动完全备份
查看>>
开发中的Warning原来也很有用
查看>>
Silverlight Toolkit例子代码中缺少System.Windows.Controls.Samples.Common.dll的解决办法
查看>>
项目经理培训后的一点感概
查看>>
vc学习之窗口大小发生变更时使控件自动摆放到合适的位置
查看>>
Oracle 获取系统日期时间,导出数据库
查看>>
黄巢的菊花,非常喜欢,贴出来共享一下
查看>>
在光纤环网中的b/s与c/s的比对
查看>>
根据程序名称和程序路径判断程序是否启动
查看>>
史记翻译-汉初三杰-萧何-萧相国世家第二十三
查看>>