当前位置: 首页 > news >正文

网站建设需注意的问题seo人员是什么意思

网站建设需注意的问题,seo人员是什么意思,提供低价网站建设,东莞网站建设营销平台的Spring源码分析 第九章 Spring Aop 源码解析 文章目录Spring源码分析前言从测试开始...系列连接前言 关于Spring框架,我们最常用的两个功能就是IOC和AOP,前几章着重分析了Ioc,下面我们接着来看AOP的源码实现。 从测试开始… /*** Ioc 容器…

Spring源码分析

第九章 Spring Aop 源码解析

文章目录

  • Spring源码分析
  • 前言
  • 从测试开始...
  • 系列连接


前言

关于Spring框架,我们最常用的两个功能就是IOC和AOP,前几章着重分析了Ioc,下面我们接着来看AOP的源码实现。


从测试开始…

/***  Ioc 容器源码分析基础案例*/
@Test
public void testAOP() {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");LagouBean lagouBean = applicationContext.getBean(LagouBean.class);lagouBean.print();
}

一路向下,一直到…产生代理对象的那个方法:

AbstractAutowireCapableBeanFactory.javaprotected Object initializeBean(final String beanName, final Object bean, @Nullable RootBeanDefinition mbd) {if (System.getSecurityManager() != null) {AccessController.doPrivileged((PrivilegedAction<Object>) () -> {invokeAwareMethods(beanName, bean);return null;}, getAccessControlContext());}else {invokeAwareMethods(beanName, bean);}Object wrappedBean = bean;if (mbd == null || !mbd.isSynthetic()) {wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);}try {invokeInitMethods(beanName, wrappedBean, mbd);}catch (Throwable ex) {throw new BeanCreationException((mbd != null ? mbd.getResourceDescription() : null),beanName, "Invocation of init method failed", ex);}if (mbd == null || !mbd.isSynthetic()) {wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);}return wrappedBean;
}

实际上这个代理对象就是由后置处理器生成的,所以我们看下applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);

@Override
public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)throws BeansException {Object result = existingBean;for (BeanPostProcessor processor : getBeanPostProcessors()) {Object current = processor.postProcessAfterInitialization(result, beanName);if (current == null) {return result;}result = current;}return result;
}

然后我们进入这个方法:

@Override
public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) {if (bean != null) {Object cacheKey = getCacheKey(bean.getClass(), beanName);if (this.earlyProxyReferences.remove(cacheKey) != bean) {return wrapIfNecessary(bean, beanName, cacheKey);}}return bean;
}

然后点击进入wrapIfNecessary包装方法

AbstractAutoProxyCreator.javaprotected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {if (StringUtils.hasLength(beanName) && this.targetSourcedBeans.contains(beanName)) {return bean;}if (Boolean.FALSE.equals(this.advisedBeans.get(cacheKey))) {return bean;}if (isInfrastructureClass(bean.getClass()) || shouldSkip(bean.getClass(), beanName)) {this.advisedBeans.put(cacheKey, Boolean.FALSE);return bean;}// 查找出和当前Bean匹配的adviceObject[] specificInterceptors = getAdvicesAndAdvisorsForBean(bean.getClass(), beanName, null);if (specificInterceptors != DO_NOT_PROXY) {this.advisedBeans.put(cacheKey, Boolean.TRUE);Object proxy = createProxy(bean.getClass(), beanName, specificInterceptors, new SingletonTargetSource(bean));this.proxyTypes.put(cacheKey, proxy.getClass());return proxy;}this.advisedBeans.put(cacheKey, Boolean.FALSE);return bean;
}

点击createProxy方法:

protected Object createProxy(Class<?> beanClass, @Nullable String beanName,@Nullable Object[] specificInterceptors, TargetSource targetSource) {if (this.beanFactory instanceof ConfigurableListableBeanFactory) {AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass);}// 创建代理的工作交给ProxyFactoryProxyFactory proxyFactory = new ProxyFactory();proxyFactory.copyFrom(this);// 判断是否要设置ProxyTargetClass为Trueif (!proxyFactory.isProxyTargetClass()) {if (shouldProxyTargetClass(beanClass, beanName)) {proxyFactory.setProxyTargetClass(true);}else {evaluateProxyInterfaces(beanClass, proxyFactory);}}// 把增强和通用的拦截器对象合并,都适配成AdvisorAdvisor[] advisors = buildAdvisors(beanName, specificInterceptors);proxyFactory.addAdvisors(advisors);// 设置参数proxyFactory.setTargetSource(targetSource);customizeProxyFactory(proxyFactory);proxyFactory.setFrozen(this.freezeProxy);if (advisorsPreFiltered()) {proxyFactory.setPreFiltered(true);}// 准备工作完成就开始创建代理return proxyFactory.getProxy(getProxyClassLoader());
}

准备工作都完成了,我们进入proxyFactory.getProxy(getProxyClassLoader());方法

public Object getProxy(@Nullable ClassLoader classLoader) {return createAopProxy().getProxy(classLoader);
}protected final synchronized AopProxy createAopProxy() {if (!this.active) {activate();}return getAopProxyFactory().createAopProxy(this);
}@Override
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {Class<?> targetClass = config.getTargetClass();if (targetClass == null) {throw new AopConfigException("TargetSource cannot determine target class: " +"Either an interface or a target is required for proxy creation.");}if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {return new JdkDynamicAopProxy(config);}return new ObjenesisCglibAopProxy(config);}else {return new JdkDynamicAopProxy(config);}
}

这⾥决定创建代理对象是用JDK Proxy,还是⽤ Cglib 了,最简单的从使用方面使用来说:设置proxyTargetClass=true强制使⽤Cglib 代理,什么参数都不设并且对象类实现了接口则默认用JDK 代理,如果没有实现接口则也必须用Cglib

@Override
public Object getProxy(@Nullable ClassLoader classLoader) {if (logger.isTraceEnabled()) {logger.trace("Creating CGLIB proxy: " + this.advised.getTargetSource());}try {Class<?> rootClass = this.advised.getTargetClass();Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy");Class<?> proxySuperClass = rootClass;if (ClassUtils.isCglibProxyClass(rootClass)) {proxySuperClass = rootClass.getSuperclass();Class<?>[] additionalInterfaces = rootClass.getInterfaces();for (Class<?> additionalInterface : additionalInterfaces) {this.advised.addInterface(additionalInterface);}}// Validate the class, writing log messages as necessary.validateClassIfNecessary(proxySuperClass, classLoader);// Configure CGLIB Enhancer...Enhancer enhancer = createEnhancer();if (classLoader != null) {enhancer.setClassLoader(classLoader);if (classLoader instanceof SmartClassLoader &&((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) {enhancer.setUseCache(false);}}enhancer.setSuperclass(proxySuperClass);enhancer.setInterfaces(AopProxyUtils.completeProxiedInterfaces(this.advised));enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);enhancer.setStrategy(new ClassLoaderAwareUndeclaredThrowableStrategy(classLoader));Callback[] callbacks = getCallbacks(rootClass);Class<?>[] types = new Class<?>[callbacks.length];for (int x = 0; x < types.length; x++) {types[x] = callbacks[x].getClass();}// fixedInterceptorMap only populated at this point, after getCallbacks call aboveenhancer.setCallbackFilter(new ProxyCallbackFilter(this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset));enhancer.setCallbackTypes(types);// Generate the proxy class and create a proxy instance.return createProxyClassAndInstance(enhancer, callbacks);}catch (CodeGenerationException | IllegalArgumentException ex) {throw new AopConfigException("Could not generate CGLIB subclass of " + this.advised.getTargetClass() +": Common causes of this problem include using a final class or a non-visible class",ex);}catch (Throwable ex) {// TargetSource.getTarget() failedthrow new AopConfigException("Unexpected AOP exception", ex);}
}

可以看见

// 配置 Cglib 增强
Enhancer enhancer = createEnhancer();
// ⽣成代理类,并且创建⼀个代理类的实例
return createProxyClassAndInstance(enhancer, callbacks);

到这里,生成代理类,并且创建⼀个代理类的实例返回

系列连接

  • Spring源码分析(一)
  • Spring源码分析(二)
  • Spring源码分析(三)
  • Spring源码分析(四)
  • Spring源码分析(五)
  • Spring源码分析(六)
  • Spring源码分析(七)
  • Spring源码分析(八)
  • Spring源码分析(九)
  • Spring源码分析(十)
http://www.lbrq.cn/news/2771983.html

相关文章:

  • wordpress ping服务列表山西seo和网络推广
  • 深圳网站的公司最近新闻大事
  • 营销型网站建设制作推广手机百度搜索引擎
  • 企业腾讯邮箱入口鄂州网站seo
  • 学做效果图的网站品牌策划是做什么的
  • 网站怎么做才有收录网站平台搭建
  • 百度做网站推广多少钱网络推广企业
  • 北京怀柔网站建设公司天津百度推广代理商
  • 大港做网站手机怎么建自己的网站
  • 益阳网站建设公司电话公司如何做网络推广营销
  • 大连做网站的科技公司网络推广员压力大吗
  • 一个服务器放多少网站seo企业优化顾问
  • 如何做wap网站西宁网站seo
  • 网站设计 图片重庆网站seo建设哪家好
  • 仙桃做网站找谁域名流量查询工具
  • 中国矿山建设网站淘宝seo优化怎么做
  • 网站论坛做斑竹自己创建个人免费网站
  • 武汉网站制作模板百度app客服电话
  • 中国贸易服务网seo自动刷外链工具
  • wordpress隐藏内容破解成都网站优化seo
  • 找做网站签证西安seo网站建设
  • 网页设计课程期末总结怎么分析一个网站seo
  • 如何看网站点击量全网营销思路
  • 美国cms是什么机构杭州排名优化软件
  • 做网页收集素材常用的网站有哪些新媒体营销策略有哪些
  • 网站的验证码是怎么做的效果好的关键词如何优化
  • 自己做视频类网站用哪个cms营销咨询
  • 做网站用新域名还是老域名东莞seo
  • 做本地旅游网站关键词怎么做快速的有排名
  • 长安网站制作公司googleplay官网
  • LeetCode 100 -- Day2
  • 云手机矩阵:重构企业云办公架构的技术路径与实践落地
  • 网络常识-SSE对比Websocket
  • java理解
  • JVM学习笔记-----StringTable
  • 快速掌握Hardhat与Solidity智能合约开发