5.Spring启动流程-postProcessBeanFactory
postProcessBeanFactory
//AnnotationConfigServletWebServerApplicationContext
protected void (ConfigurableListableBeanFactory beanFactory) {
super.postProcessBeanFactory(beanFactory);
//默认情况这里basePackages为空
if (this.basePackages != null && this.basePackages.length > 0) {
this.scanner.scan(this.basePackages);
}
//默认情况这里annotatedClasses也为空
if (!this.annotatedClasses.isEmpty()) {
this.reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
}
//ServletWebServerApplicationContext
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
beanFactory.addBeanPostProcessor(new WebApplicationContextServletContextAwareProcessor(this));
beanFactory.ignoreDependencyInterface(ServletContextAware.class);
this.registerWebApplicationScopes();
}
registerWebApplicationScopes
private void registerWebApplicationScopes() {
ServletWebServerApplicationContext.ExistingWebApplicationScopes existingScopes = new ServletWebServerApplicationContext.ExistingWebApplicationScopes(this.getBeanFactory());
WebApplicationContextUtils.registerWebApplicationScopes(this.getBeanFactory());
existingScopes.restore();
}
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory) {
registerWebApplicationScopes(beanFactory, (ServletContext)null);
}
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, @Nullable ServletContext sc) {
beanFactory.registerScope("request", new RequestScope());
beanFactory.registerScope("session", new SessionScope());
//默认情况下,这里sc是空
if (sc != null) {
ServletContextScope appScope = new ServletContextScope(sc);
beanFactory.registerScope("application", appScope);
sc.setAttribute(ServletContextScope.class.getName(), appScope);
}
beanFactory.registerResolvableDependency(ServletRequest.class, new WebApplicationContextUtils.RequestObjectFactory());
beanFactory.registerResolvableDependency(ServletResponse.class, new WebApplicationContextUtils.ResponseObjectFactory());
beanFactory.registerResolvableDependency(HttpSession.class, new WebApplicationContextUtils.SessionObjectFactory());
beanFactory.registerResolvableDependency(WebRequest.class, new WebApplicationContextUtils.WebRequestObjectFactory());
if (jsfPresent) {
WebApplicationContextUtils.FacesDependencyRegistrar.registerFacesDependencies(beanFactory);
}
}
这里居然添加了一个BeanPostProcessor 而不是BeanFactoryPostProcessor
到此为止已经有三个了 前两是在prepareBeanFactory过程中添加的
0 = {ApplicationContextAwareProcessor@3961}
1 = {ApplicationListenerDetector@3962}
2 = {WebApplicationContextServletContextAwareProcessor@4032}
看起来也没啥用
先不管他