摘要: 一 配置xml方式:扫描com包下的bean com包下一个类: resource下 p.properties中的文件内容: main函数: 打印: hahadaxiao 二 注解方式 com包下存在下面这个类,默认扫描Config1所在的包下的Bean 打印: hahadaxiao 阅读全文
posted @ 2017-03-14 23:04 lh_cn 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 工程 resource下新建一个 p.properties文件,里面内容为: 使用: 打印: hahadaxiao 若有多个properties文件,则用 *号通配符,或者用逗号分隔 阅读全文
posted @ 2017-03-14 22:48 lh_cn 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1.延迟加载 2.Bean作用域 3.生命周期 打印: init destory 效果一样。 阅读全文
posted @ 2017-03-14 22:37 lh_cn 阅读(761) 评论(0) 推荐(0) 编辑
摘要: 1.普通bean是用id标志,context.getBean时传入名称即可获得。 2.通过alias给bean命别名。 3.注解在Bean括号中写上名字。 阅读全文
posted @ 2017-03-14 21:49 lh_cn 阅读(341) 评论(0) 推荐(0) 编辑
摘要: Person类实现 ApplicationContextAware ,在创建该bean的时候,会将context注入到bean中。 打印: p1name=p1 阅读全文
posted @ 2017-03-14 21:34 lh_cn 阅读(862) 评论(0) 推荐(0) 编辑
摘要: 无法编译通过,报错。构造函数注入不能循环依赖. 阅读全文
posted @ 2017-03-14 21:27 lh_cn 阅读(1429) 评论(0) 推荐(0) 编辑
摘要: 打印: config2 person 因为 则打印: config1 person 阅读全文
posted @ 2017-03-14 21:18 lh_cn 阅读(998) 评论(0) 推荐(0) 编辑
摘要: 通过工厂创建bean。 运行打印: staticCreate instanceCreate 注解方式: 输出: staticCreateinstanceCreate 阅读全文
posted @ 2017-03-14 21:00 lh_cn 阅读(422) 评论(0) 推荐(0) 编辑
摘要: 打印: Person person person ...leader leader leader ...Group group... 使用depends-on可以设置bean依赖,只有depends-on列表中的bean才会被创建。 阅读全文
posted @ 2017-03-14 20:44 lh_cn 阅读(1021) 评论(0) 推荐(0) 编辑
摘要: 1.自动装配 1.1 byType 1.1.1根据类型自动匹配,若当前没有类型可以注入或者存在多个类型可以注入,则失败。必须要有对于的setter方法 public class Person{ public String name; public int age; public String get 阅读全文
posted @ 2017-03-14 20:13 lh_cn 阅读(196) 评论(0) 推荐(0) 编辑