本篇内容介绍了“springboot如何完善上下文加载器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联建站总部坐落于成都市区,致力网站建设服务有成都网站建设、网站设计、网络营销策划、网页设计、网站维护、公众号搭建、微信小程序开发、软件开发等为企业提供一整套的信息化建设解决方案。创造真正意义上的网站建设,为互联网品牌在互动行销领域创造价值而不懈努力!
1. prepareContext
源码:
```
private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
//注入环境属性
context.setEnvironment(environment);
//上下文后置处理
this.postProcessApplicationContext(context);
//完善初始化类的属性
this.applyInitializers(context);
//发送监听事件
listeners.contextPrepared(context);
//日志
if (this.logStartupInfo) {
this.logStartupInfo(context.getParent() == null);
this.logStartupProfileInfo(context);
}
//注册传入的配置参数为bean,这里将传入的参数封装成applicationArguments,内部类似命令行
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("springApplicationArguments", applicationArguments);
//banner打印
if (printedBanner != null) {
beanFactory.registerSingleton("springBootBanner", printedBanner);
}
//这里默认情况下bean定义不允许重复
if (beanFactory instanceof DefaultListableBeanFactory) {
((DefaultListableBeanFactory)beanFactory).setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
}
//默认不开启延迟加载
if (this.lazyInitialization) {
context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor());
}
//获取全部的资源
//这里获取了启动类的资源和 当前SpringApplication中的source资源。
//到目前来说实际上只有启动类资源
Set