這個(gè)最好從源頭理解:
->AbstractAutowireCapableBeanFactory.initializeBean
實(shí)例化bean的時(shí)候調(diào)用
->AbstractAutowireCapableBeanFactory.invokeAwareMethods
private void invokeAwareMethods(final String beanName, final Object bean) {
if (bean instanceof Aware) {
if (bean instanceof BeanNameAware) {
((BeanNameAware) bean).setBeanName(beanName);
}
if (bean instanceof BeanClassLoaderAware) {
ClassLoader bcl = getBeanClassLoader();
if (bcl != null) {
((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);
}
}
if (bean instanceof BeanFactoryAware) {
((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
}
}
}
d56b4c068e76 評(píng)論自Spring中的aware接口