Why use @PostConstruct?
2016-05-19 11:58
183 查看
question:
In a managed bean,
called after the regular Java object constructor.
Why would I use
initialize by bean, instead of the regular constructor itself?
the response:
because when the constructor is called, the bean is not yet initialized - i.e. no dependencies are injected. In the
the bean is fully initialized and you can use the dependencies.
because this is the contract that guarantees that this method will be invoked only once in the bean lifecycle. It may happen (though unlikely) that a bean is instantiated multiple times by the container in its internal working, but it guarantees that
be invoked only once.z
下边人的讨论
http://stackoverflow.com/questions/3406555/why-use-postconstruct
In a managed bean,
@PostConstructis
called after the regular Java object constructor.
Why would I use
@PostConstructto
initialize by bean, instead of the regular constructor itself?
the response:
because when the constructor is called, the bean is not yet initialized - i.e. no dependencies are injected. In the
@PostConstructmethod
the bean is fully initialized and you can use the dependencies.
because this is the contract that guarantees that this method will be invoked only once in the bean lifecycle. It may happen (though unlikely) that a bean is instantiated multiple times by the container in its internal working, but it guarantees that
@PostConstructwill
be invoked only once.z
下边人的讨论
|
相关文章推荐
- php 字符串函数
- Android学习路线
- angular中的等号(==)判定
- jquery数组删除指定元素的方法:grep()
- 进程间通信方式及比较
- Vim 插件管理
- 数据库设计基本知识
- Execution failed for task ':dexWandoujiaDebug'. > Multi dex requires Build Tools 21.0.0 / Current: 2
- sqoop
- 20个正则表达式
- 手机访问电脑搭建的服务器地址
- 控制 C++生成随机数的范围
- 底层解惑-spring的@service的原理及其一接口多实现的解决方案
- Python -- 语法和变量
- 检测苹果设备是否越狱
- Swift学习第五枪
- [Java] 网页相对URL解析
- java.sql.SQLException: Unknown system variable 'tx_read_only'
- 基于Echarts 3.19 制作常用的图形(非静态)
- RxJava 与 Retrofit 结合的最佳实践