Spring Bean扩展接口 -- InitializingBean源码分析
2017-01-09 18:34
435 查看
一、首先我们看一下InitializingBean接口的源码
package org.springframework.beans.factory;
public interface InitializingBean {
void afterPropertiesSet() throws Exception;
}
InitializingBean接口只要一个方法afterPropertiesSet,下面实例我们对afterPropertiesSet进行解释。
二、实例
@Component
public class OrderTest implements InitializingBean {
String name ;
public String getName() {
return name;
}
// 当容器启动后,先执行此处
public void setName(String name) {
System.out.println("this name is InitializingBean");
this.name = name;
}
// 当所有的属性都设置完成后,才会执行afterPropertiesSet方法
public void afterPropertiesSet() throws Exception {
System.out.println("exe afterPropertiesSet");
}
}
当容器启动后结果为:
this
name is InitializingBean
exe
afterPropertiesSet
package org.springframework.beans.factory;
public interface InitializingBean {
void afterPropertiesSet() throws Exception;
}
InitializingBean接口只要一个方法afterPropertiesSet,下面实例我们对afterPropertiesSet进行解释。
二、实例
@Component
public class OrderTest implements InitializingBean {
String name ;
public String getName() {
return name;
}
// 当容器启动后,先执行此处
public void setName(String name) {
System.out.println("this name is InitializingBean");
this.name = name;
}
// 当所有的属性都设置完成后,才会执行afterPropertiesSet方法
public void afterPropertiesSet() throws Exception {
System.out.println("exe afterPropertiesSet");
}
}
当容器启动后结果为:
this
name is InitializingBean
exe
afterPropertiesSet
相关文章推荐
- 微服务框架Spring Cloud介绍 Part2: Spring Cloud与微服务
- springmvc实现url路由功能
- spring aop 无法代理父类方法 的解决方法
- Spring MVC过滤器-超类 GenericFilterBean
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- Spring AOP动态代理-切面
- 使用MVC微信支付返回get_brand_wcpay_request:fail
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- PHP strtotime函数用法、实现原理和源码分析
- jQuery 源码分析笔记(3) Deferred机制
- jQuery 源码分析笔记(5) jQuery.support
- jQuery-1.9.1源码分析系列(十)事件系统之事件包装
- java 中Spring task定时任务的深入理解
- 模拟Spring的简单实现