Spring boot源码分析-AnnotationConfigEmbeddedWebApplicationContext默认web环境下的启动容器(3)

Spring boot源码分析-AnnotationConfigEmbeddedWebApplicationContext默认web环境下的启动容器(3)

首先我们看容器的类图,相比于

看看这个图和AnnotationConfigApplicationContext有什么不一样的地方
1.GenericWebApplicationContext继承了GenericApplicationContext实现了ConfigurableWebApplicationContext接口 我们看一下这个接口,主要提供了web容器也就是servlet容器的相关操作

2.再看AnnotationConfigEmbeddedWebApplicationContext 容器重写了
AbstractApplicationContext的模板方法,在同期中提供了WebApplicationContextServletContextAwareProcessor的处理器,提供了容器注入的功能

protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
}
public class AnnotationConfigEmbeddedWebApplicationContext
        extends EmbeddedWebApplicationContext {

    private final AnnotatedBeanDefinitionReader reader;

    private final ClassPathBeanDefinitionScanner scanner;

    private Class<?>[] annotatedClasses;

    private String[] basePackages;

    ······

    @Override
    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        super.postProcessBeanFactory(beanFactory);
        if (this.basePackages != null && this.basePackages.length > 0) {
            this.scanner.scan(this.basePackages);
        }
        if (this.annotatedClasses != null && this.annotatedClasses.length > 0) {
            this.reader.register(this.annotatedClasses);
        }
    }

    }

EmbeddedWebApplicationContext

public class EmbeddedWebApplicationContext extends GenericWebApplicationContext {

······

@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        beanFactory.addBeanPostProcessor(
                new WebApplicationContextServletContextAwareProcessor(this));
        beanFactory.ignoreDependencyInterface(ServletContextAware.class);
    }
}
  • 其他的功能基本和AnnotationConfigApplicationContext类似 可以去看上一章的解释
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值