protectedObjectcreateBean(String beanName,RootBeanDefinition mbd,@NullableObject[] args)throwsBeanCreationException{if(logger.isTraceEnabled()){logger.trace("Creating instance of bean '"+ beanName +"'");}//到这个方法创建Bean的时候beanDefinition的类型必须是RootBeanDefinition//RootBeanDefinition是顶级的父类BeanDefinition,是不允许再有父亲的BeanDefinition的//在调用这个方法之前,是会进行BeanDefinition的封装和合并的RootBeanDefinition mbdToUse = mbd;// Make sure bean class is actually resolved at this point, and// clone the bean definition in case of a dynamically resolved Class// which cannot be stored in the shared merged bean definition.//加载beanclass,将bean的class拿出来加载到jvm中Class<?> resolvedClass =resolveBeanClass(mbd, beanName);if(resolvedClass !=null&&!mbd.hasBeanClass()&& mbd.getBeanClassName()!=null){//加载成功过后,然后创建一个对象RootBeanDefinition,这个RootBeanDefinition就是最终创建的单例对象放入到单例池mbdToUse =newRootBeanDefinition(mbd);mbdToUse.setBeanClass(resolvedClass);}// Prepare method overrides.try{//检查是否有方法重载 避免args类型检查开销//lookup-mehtod标签 replace-method 标签mbdToUse.prepareMethodOverrides();}catch(BeanDefinitionValidationException ex){thrownewBeanDefinitionStoreException(mbdToUse.getResourceDescription(),beanName,"Validation of method overrides failed", ex);}try{// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.//上面的的英文是官方解释:给一个创建一个代理对象bean的机会在bean的后置处理器中//简单来说就是这里是提供给程序员实现的方法,比如你想代理一些bean,那么你就可以实现相关的后置处理器//比如aop,或者你想为一些bean添加一些职责,那么只要返回不为空,spring就不会为你创建bean了,会直接用你创建的bean//这个方法可以叫做bean的实例化前,可以简单这样理解Object bean =resolveBeforeInstantiation(beanName, mbdToUse);if(bean !=null){return bean;}}catch(Throwable ex){thrownewBeanCreationException(mbdToUse.getResourceDescription(), beanName,"BeanPostProcessor before instantiation of bean failed", ex);}try{//这个创建bean是spring容器自带的创建bean,也就是代码走到这里,则证明需要spring来创建bean了//一般在spring项目中,普通的bean一般都会在这里由spring来创建,而特殊的Bean可能在上面由resolveBeforeInstantiation//来直接创建了Object beanInstance =doCreateBean(beanName, mbdToUse, args);if(logger.isTraceEnabled()){logger.trace("Finished creating instance of bean '"+ beanName +"'");}return beanInstance;}catch(BeanCreationException|ImplicitlyAppearedSingletonException ex){// A previously detected exception with proper bean creation context already,// or illegal singleton state to be communicated up to DefaultSingletonBeanRegistry.throw ex;}catch(Throwable ex){thrownewBeanCreationException(mbdToUse.getResourceDescription(), beanName,"Unexpected exception during bean creation", ex);}}
/*** Apply before-instantiation post-processors, resolving whether there is a* before-instantiation shortcut for the specified bean.* @param beanName the name of the bean* @param mbd the bean definition for the bean* @return the shortcut-determined bean instance, or {@code null} if none* 这个方法其实就是调用bean的后置处理器,bean的后置处理器有点多,分为* 实例化前、实例化后、调用aware后、初始化前、初始化后* 而下面这个方法就是在bean的实例化之前调用的,而这个方法是返回一个对象* 所以如果说你这个方法调用完毕过后,返回的一个对象不为空,那么就说明你的bean已经存在了,已经有了* 那么就不会在调用你后面的调用aware就是不会再调用spring提供的创建Bean的方法了* 但是如果applyBeanPostProcessorsBeforeInstantiation返回的对象不为空,那么spring还猜想你可能还有* 实例化的一些操作,所以这里还要调用那个实例化后的bean后置处理器applyBeanPostProcessorsAfterInitialization* 按正常的逻辑,spring会通过实例化前、实例化后、调用aware后、初始化前、初始化后来调用后置处理器,但是下的这个方法* 是你人为的干预了spring的实例化和初始化,那么你既然实例化了,那么就自己去调用初始化后的一些后置处理器,* 请注意,这个方法也不会调用后面的aware方法了*/@NullableprotectedObjectresolveBeforeInstantiation(String beanName,RootBeanDefinition mbd){Object bean =null;if(!Boolean.FALSE.equals(mbd.beforeInstantiationResolved)){// Make sure bean class is actually resolved at this point.if(!mbd.isSynthetic()&&hasInstantiationAwareBeanPostProcessors()){Class<?> targetType =determineTargetType(beanName, mbd);if(targetType !=null){//是调用的bean的实例化的后置处理器bean =applyBeanPostProcessorsBeforeInstantiation(targetType, beanName);if(bean !=null){//如果返回的bean不为空,则证明spring不会去调用它自己的createBean方法了,因为你返回了对象//所以下面还要看你有没有自己的bean初始化后的逻辑,如果有就调用,所以卫生么这个方法有//bean的实例化前的方法和bean初始化后的方法//是调用的bean的初始化后置处理器bean =applyBeanPostProcessorsAfterInitialization(bean, beanName);}}}mbd.beforeInstantiationResolved =(bean !=null);}return bean;}
protectedObjectdoCreateBean(String beanName,RootBeanDefinition mbd,@NullableObject[] args)throwsBeanCreationException{// Instantiate the bean.BeanWrapper instanceWrapper =null;if(mbd.isSingleton()){//单例bean//从缓存中获取instanceWrapper =this.factoryBeanInstanceCache.remove(beanName);}if(instanceWrapper ==null){//没有 则创建bean//bean的实例化,里面包含了推断构造方法,简单来说就是对bean进行实例化,这个方法后面来讲instanceWrapper =createBeanInstance(beanName, mbd, args);}Object bean = instanceWrapper.getWrappedInstance();Class<?> beanType = instanceWrapper.getWrappedClass();if(beanType !=NullBean.class){mbd.resolvedTargetType = beanType;}// Allow post-processors to modify the merged bean definition.synchronized(mbd.postProcessingLock){if(!mbd.postProcessed){try{//spring提供的又一个bean后置处理器,就是在bean实例化完成过后,可以进行调用//这个后置处理器可以传入指定的BeanDefinition,也就是你可以改变BeanDefinition的属性//但是这个时候bean都已经实例化完成了,就算你修改了beanclass也没有用了//但是有些属性我们还是可以设置的,比如可以手动设置初始化的方法mbd.setInitMethodName//@AutoWired注解的切入点就是在这个后置处理器中找到的并且注入到缓存中applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);}catch(Throwable ex){thrownewBeanCreationException(mbd.getResourceDescription(), beanName,"Post-processing of merged bean definition failed", ex);}mbd.postProcessed =true;}}// Eagerly cache singletons to be able to resolve circular references// even when triggered by lifecycle interfaces like BeanFactoryAware.//当前bean 是否需要早期暴露boolean earlySingletonExposure =(mbd.isSingleton()&&this.allowCircularReferences &&isSingletonCurrentlyInCreation(beanName));if(earlySingletonExposure){if(logger.isTraceEnabled()){logger.trace("Eagerly caching bean '"+ beanName +"' to allow for resolving potential circular references");}//和循环依赖有关,后面讲addSingletonFactory(beanName,()->getEarlyBeanReference(beanName, mbd, bean));}// Initialize the bean instance.Object exposedObject = bean;try{/*** 填充属性,处理@AutoWried,调用bean的实例化后的方法*/populateBean(beanName, mbd, instanceWrapper);/*** 这个方法是调用bean的初始化方法的*/exposedObject =initializeBean(beanName, exposedObject, mbd);}catch(Throwable ex){if(ex instanceofBeanCreationException&& beanName.equals(((BeanCreationException) ex).getBeanName())){throw(BeanCreationException) ex;}else{thrownewBeanCreationException(mbd.getResourceDescription(), beanName,"Initialization of bean failed", ex);}}//下面是依赖注入的代码,这个后面说if(earlySingletonExposure){Object earlySingletonReference =getSingleton(beanName,false);if(earlySingletonReference !=null){if(exposedObject == bean){exposedObject = earlySingletonReference;}elseif(!this.allowRawInjectionDespiteWrapping &&hasDependentBean(beanName)){String[] dependentBeans =getDependentBeans(beanName);Set<String> actualDependentBeans =newLinkedHashSet<>(dependentBeans.length);for(String dependentBean : dependentBeans){if(!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)){actualDependentBeans.add(dependentBean);}}if(!actualDependentBeans.isEmpty()){thrownewBeanCurrentlyInCreationException(beanName,"Bean with name '"+ beanName +"' has been injected into other beans ["+StringUtils.collectionToCommaDelimitedString(actualDependentBeans)+"] in its raw version as part of a circular reference, but has eventually been "+"wrapped. This means that said other beans do not use the final version of the "+"bean. This is often the result of over-eager type matching - consider using "+"'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.");}}}}// Register bean as disposable.try{registerDisposableBeanIfNecessary(beanName, bean, mbd);}catch(BeanDefinitionValidationException ex){thrownewBeanCreationException(mbd.getResourceDescription(), beanName,"Invalid destruction signature", ex);}return exposedObject;}
/*** Add the given singleton factory for building the specified singleton* if necessary.* <p>To be called for eager registration of singletons, e.g. to be able to* resolve circular references.* @param beanName the name of the bean* @param singletonFactory the factory for the singleton object* 将ObjectFactory 添加到三级缓存中*/protectedvoidaddSingletonFactory(String beanName,ObjectFactory<?> singletonFactory){Assert.notNull(singletonFactory,"Singleton factory must not be null");synchronized(this.singletonObjects){if(!this.singletonObjects.containsKey(beanName)){this.singletonFactories.put(beanName, singletonFactory);this.earlySingletonObjects.remove(beanName);this.registeredSingletons.add(beanName);}}}
VMware17创建新虚拟机:
1.静态设置与关闭防火墙
在终端命令行依次输入:
1)cd /etc
2) ls
3) cd sysconfig/
4) cd network-scripts/
5) ls
6) vi ifcfg-nes33
在cmd命令栏输入:ncpa.cpl,是找网络适配器的命令
IPADDR&qu…
在jupyter notebook中使用conda环境
1. 环境配置
conda activate my-conda-env # this is the environment for your project and code
conda install ipykernel
conda deactivateconda activate base # could be also some other environment
conda install nb_cond…