由Mybatis发现的一个坑
来源:互联网 发布:牵引变电所接地网优化 编辑:程序博客网 时间:2024/05/17 08:57
源码很重要
Thanks for the report, Osvaldas. This has indeed been an issue known about, at least internally, for some time.
There is a fundamental lifecycle conflict in handling BeanFactoryPostProcessor @Bean methods within @Configuration classes that use @Autowired, @PostConstruct, @Value, etc. Because BFPPs must be instantiated early in the lifecycle, they cause early instantiation of their declaring @Configuration class - too early to recieve the usual post-processing by AutowiredAnnotationBeanPostProcessor and friends.
To resolve this issue, it is now possible to declare @Bean methods as static. This permits the container to detect and invoke these methods without instantiating the @Configuration class, thus avoiding the aforementioned lifecycle issues.
@Bean Javadoc has been updated to reflect, and the commit comment follows:
Author: Chris Beams <cbeams@vmware.com>
Date: Tue May 10 18:17:26 2011 +0800
Allow static modifier on @Bean methods
Declaring @Bean methods as 'static' is now permitted, whereas previously
it raised an exception at @Configuration class validation time.
A static @Bean method can be called by the container without requiring
the instantiation of its declaring @Configuration class. This is
particularly useful when dealing with BeanFactoryPostProcessor beans,
as they can interfere with the standard post-processing lifecycle
necessary to handle @Autowired, @Inject, @Value, @PostConstruct and
other annotations.
static @Bean methods cannot recieve CGLIB enhancement for scoping and
AOP concerns. This is acceptable in BFPP cases as they rarely if ever
need it, and should not in typical cases ever be called by another
@Bean method. Once invoked by the container, the resulting bean will
be cached as usual, but multiple invocations of the static @Bean method
will result in creation of multiple instances of the bean.
static @Bean methods may not, for obvious reasons, refer to normal
instance @Bean methods, but again this is not likely a concern for BFPP
types. In the rare case that they do need a bean reference, parameter
injection into the static @Bean method is technically an option, but
should be avoided as it will potentially cause premature instantiation
of more beans that the user may have intended.
Note particularly that a WARN-level log message is now issued for any
non-static @Bean method with a return type assignable to BFPP. This
serves as a strong recommendation to users that they always mark BFPP
@Bean methods as static.
See @Bean Javadoc for complete details.
Issue: SPR-8257, SPR-8269
- 由Mybatis发现的一个坑
- 一个由库表到POJO的myBatis配置文件建立的例子
- 由一个内存错误发现的cocos2dx 引擎3.4版本的 一个bug
- 由一个LED闪烁问题发现的MTK的LED driver中存在的问题
- 由string删除某个字符的操作发现的一个问题
- mybatis 的一个坑
- VC的一个发现...
- 我的一个发现
- FileGeodatabase的一个发现
- 我的一个发现
- 一个666的发现
- 由ORA-00979错误发现ORACLE一个BUG
- 发现一个以前不会发现的虫子
- Mybatis语法错误的一个坑
- 使用mybatis的一个坑
- 当函数发现字符串中如果有一个地方由一个或多个连续的空格组成,就把它们改成单个空格字符。
- 由Emoji表情发现的JNI GetStringUTFChars()隐藏的问题
- python 命令行的一个发现...
- 双十一快到了,剁手党们准备好了吗,快来看看优惠卷商城吧
- Java Security Architecture--Java安全体系技术文档翻译(二)
- HttpClient--入门
- 彻底理解android 建造者模式
- 【算法】常用算法之快速排序算法
- 由Mybatis发现的一个坑
- Mac截图
- 一个18届程序媛的offer血泪史
- CSRF XSS(XSRF) CORS OPTIONS(HTTP)概念理解
- 笔记_计算机网络_Python socket编程
- 代理模式
- Android Activity生命周期详解
- android 6.0运行时权限
- HDU 1024 Max Sum Plus Plus【DP+滚动数组】