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

做3d模型的叫什么牛的网站绍兴金圣建设有限公司网站

做3d模型的叫什么牛的网站,绍兴金圣建设有限公司网站,信阳做房产哪个网站好用,oss cdn wordpress对Spring AOP的理解 OOP表示面向对象编程#xff0c;是一种编程思想#xff0c;AOP表示面向切面编程#xff0c;也是一种编程思想 Spring AOP#xff1a;Spring为了让程序员更加方便的做到面向切面编程所提供的技术支持 Spring提供的一套机制#xff0c;让我们更容易的…对Spring AOP的理解 OOP表示面向对象编程是一种编程思想AOP表示面向切面编程也是一种编程思想 Spring AOPSpring为了让程序员更加方便的做到面向切面编程所提供的技术支持 Spring提供的一套机制让我们更容易的进行AOP这套机制就是Spring AOP 扩展用注解的方式来定义Pointcut和AdviceSpring并不是首创首创是 AspectJ。JBoss 4.0、aspectwerkz 等技术也提供了对于AOP的支持。 Spring是依赖了AspectJ的Spring觉得AspectJ中的Before、Around等注解比较好用所以把这些注解直接拿过来用但是注解底层的解析是由Spring自己做的。 所以我们在用 Spring时如果你想用Before、Around等注解是需要单独引入aspecj相关jar包的 compile group: org.aspectj, name: aspectjrt, version: 1.9.5 compile group: org.aspectj, name: aspectjweaver, version: 1.9.5 注意AspectJ它自己也是一个项目是在编译时对字节码进行了修改可以理解为是在编译时就会去解析Before这些注解然后得到代理逻辑加入到被代理类的字节码中去所以如果想用AspectJ技术来生成代理对象 是需要用单独的AspectJ编译器的。项目中很少用AspectJ编译器只是用了Before这些注解在启动Spring的过程中会去解析这些注解然后利用动态代理机制生成代理对象。 AOP中的概念 Spring官网 Let us begin by defining some central AOP concepts and terminology. These terms are not Spring-specific. Unfortunately, AOP terminology is not particularly intuitive. However, it would be even more confusing if Spring used its own terminology 翻译AOP中的这些概念不是Spring特有的不幸的是AOP中的概念不是特别直观的但是如果Spring重新定义自己的那可能会导致更加混乱 1、Aspect表示切面比如被Aspect注解的类就是切面可以在切面中去定义Pointcut、Advice等等 2、Join point表示连接点表示一个程序在执行过程中的一个点比如一个方法的执行比如一个异常的处理在Spring AOP中一个连接点通常表示一个方法的执行 3、Advice表示通知表示在一个特定连接点上所采取的动作。很多AOP框架中包括Spring会用Interceptor拦截器来实现Advice并且在连接点周围维护一个Interceptor链 4、Pointcut表示切点用来匹配一个或多个连接点Advice与切点表达式是关联在一起的Advice将会执行在和切点表达式所匹配的连接点上 5、Introduction可以使用DeclareParents来给所匹配的类添加一个接口并指定一个默认实现 6、Target object目标对象被代理对象 7、AOP proxy表示代理工厂用来创建代理对象的在Spring Framework中要么是JDK动态代理要么是CGLIB代理 8、Weaving表示织入表示创建代理对象的动作这个动作可以发生在编译时期比如Aspejctj或者运行时比如Spring AOP Advice在Spring AOP中对应的API Aspject中用五个注解来定义Advice表示代理逻辑以及执行时机Spring有提供类似执行时机的实现类 Aspject注解代理逻辑、执行时机Spring实现类类似执行时机Spring解析注解为对应的Advice类Before接口MethodBeforeAdvice 继承了接口BeforeAdviceAspectJMethodBeforeAdvice实际上是MethodBeforeAdviceAfterReturning接口AfterReturningAdviceAspectJAfterReturningAdvice实际上是AfterReturningAdviceAfterThrowing接口ThrowsAdviceAspectJAfterThrowingAdvice实际上是MethodInterceptorAfter接口AfterAdviceAspectJAfterAdvice实际上是MethodInterceptorAround接口MethodInterceptorAspectJAroundAdvice实际上是MethodInterceptor TargetSource的使用 日常的AOP中被代理对象就是Bean对象是由BeanFactory创建出来的。 Spring AOP中提供了TargetSource机制可以用自定义逻辑来创建被代理对象。 Lazy注解当加在属性上时会产生一个代理对象赋值给这个属性 /*** Complete implementation of the* {link org.springframework.beans.factory.support.AutowireCandidateResolver} strategy* interface, providing support for qualifier annotations as well as for lazy resolution* driven by the {link Lazy} annotation in the {code context.annotation} package.** author Juergen Hoeller* since 4.0*/ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotationAutowireCandidateResolver {OverrideNullablepublic Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, Nullable String beanName) {// 判断是不是懒注入AutowiredLazy// 如果是则会在注入时生成一个代理对象注入给属性所以懒注入并不代表属性为nullreturn (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null);}protected boolean isLazy(DependencyDescriptor descriptor) {for (Annotation ann : descriptor.getAnnotations()) {Lazy lazy AnnotationUtils.getAnnotation(ann, Lazy.class);if (lazy ! null lazy.value()) {return true;}}MethodParameter methodParam descriptor.getMethodParameter();if (methodParam ! null) {Method method methodParam.getMethod();if (method null || void.class method.getReturnType()) {Lazy lazy AnnotationUtils.getAnnotation(methodParam.getAnnotatedElement(), Lazy.class);if (lazy ! null lazy.value()) {return true;}}}return false;}protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final Nullable String beanName) {BeanFactory beanFactory getBeanFactory();Assert.state(beanFactory instanceof DefaultListableBeanFactory,BeanFactory needs to be a DefaultListableBeanFactory);final DefaultListableBeanFactory dlbf (DefaultListableBeanFactory) beanFactory;TargetSource ts new TargetSource() {Overridepublic Class? getTargetClass() {return descriptor.getDependencyType();}Overridepublic boolean isStatic() {return false;}Overridepublic Object getTarget() {SetString autowiredBeanNames (beanName ! null ? new LinkedHashSet(1) : null);Object target dlbf.doResolveDependency(descriptor, beanName, autowiredBeanNames, null);if (target null) {Class? type getTargetClass();if (Map.class type) {return Collections.emptyMap();}else if (List.class type) {return Collections.emptyList();}else if (Set.class type || Collection.class type) {return Collections.emptySet();}throw new NoSuchBeanDefinitionException(descriptor.getResolvableType(),Optional dependency not present for lazy injection point);}if (autowiredBeanNames ! null) {for (String autowiredBeanName : autowiredBeanNames) {if (dlbf.containsBean(autowiredBeanName)) {dlbf.registerDependentBean(autowiredBeanName, beanName);}}}return target;}Overridepublic void releaseTarget(Object target) {}};// ProxyFactory生成代理对象并使用了TargetSource// 所以代理对象在执行某个方法时调用TargetSource的getTarget()方法实时得到一个被代理对象ProxyFactory pf new ProxyFactory();pf.setTargetSource(ts);Class? dependencyType descriptor.getDependencyType();if (dependencyType.isInterface()) {pf.addInterface(dependencyType);}return pf.getProxy(dlbf.getBeanClassLoader());} } IntroductionDeclareParents简介 Spring官网对Introduction和相关注解DeclareParents的介绍 Introductions (known as inter-type declarations in AspectJ) enable an aspect to declare that advised objects implement a given interface, and to provide an implementation of that interface on behalf of those objects. An introduction is made using the DeclareParents annotation. This annotation is used to declare that matching types have a new parent (hence the name). Introduction有什么用呢 可以给一个已有的类引入新的接口在不修改原类的情况下做一些扩展行为 比如说生产上正在提供服务这个时候想要加一个验证功能就可以通过DeclareParents注解实现 如何使用DeclareParents注解 // 第一步添加一个接口 package com.gax.aop; public interface Verifier {boolean validate(User user); }// 第二步给接口添加一个实现类 package com.gax.aop; public class BasicVerifier implements Verifier {Overridepublic boolean validate(User user){if (user.getName().equals(gc) user.getPass().equals(6174)){return true;}return false;} }// 第三步使用DeclareParents注解关联新增接口和原来的类 Aspect Component public class MyAspect {DeclareParents(value com.gax.service.UserService,defaultImpl com.gax.aop.BasicVerifier.class)public Verifier verifer; }// 第四步测试效果 public class Test {public static void main(String[] args){User user new User();user.setPass(6174888);user.setName(gc);// 创建一个Spring容器AnnotationConfigApplicationContext applicationContext new AnnotationConfigApplicationContext(AppConfig.class);UserService userService (UserService) applicationContext.getBean(userService);// 注意这里Verifier是一个接口Verifier verifier (Verifier) userService;// 验证通过才能提供服务if(verifier.validate(user)){userService.service();}} }// AppConfig指定扫描包 ComponentScan(value com.gax) //EnableAspectJAutoProxy Import(AnnotationAwareAspectJAutoProxyCreator.class) public class AppConfig { }Data public class User {private String name;private String pass; } EnableAspectJAutoProxy Import(AnnotationAwareAspectJAutoProxyCreator.class) 某些情况下上面这两种写法等价。EnableAspectJAutoProxy注解内部其实就是注册了一个AnnotationAwareAspectJAutoProxyCreator AnnotationAwareAspectJAutoProxyCreator其实就是一个BeanPostProcessor在Spring启动过程中可以去解析AspectJ的注解 参考文章https://www.cnblogs.com/powerwu/articles/5170861.html LoadTimeWeaver 参考文章https://www.cnblogs.com/davidwang456/p/5633609.html
http://www.eeditor.cn/news/121145/

相关文章:

  • 网站优化效果什么网站做蜘蛛池
  • 郓城做网站深圳创业补贴政策2023申请条件
  • 电子厂网站建设方案书怎么写企业手机网站建设市场
  • 网站设计制作需要多少钱常州网络优化排名
  • 网站备案 内容简易网站制作软件
  • dedecms精仿学校网站模板巨好用网络企业管理系统
  • 建设银行的积分网站ps网页设计步骤
  • 企业网站导航优化网站开发答辩会问哪些问题
  • 网站开发技术背景介绍桂林生活网二手房
  • 山东建设厅网站网址做网站找那家公司好
  • 网站改版html绵阳网站建设联系电话
  • 电话怎么做网站推广互联网大会
  • 晋中做网站的公司建设网站需要的步骤
  • 女装网站源码 带支付接口百度关键词屏蔽
  • 中企动力网站培训国外网站购物
  • 哪些有名网站是用php做的静态网站设计与制作书籍
  • 网站开发的试用期条款dtc建站服务
  • 遵义花果园网站建设创建一个网站多少钱
  • 政务网站建设及管理搜启网站建设
  • 网站开发的未来发展零基础电商怎么做
  • 爱射影院网站建设中中国最好的建筑公司
  • 网站建设的主要观点软件下载网站怎么赚钱
  • 山西长治做网站公司网站推广计划书具体包含哪些基本内容?
  • 1建设网站的重要性网站建设的一般过程包括哪些方面
  • seo快速排名网站优化昌江区网站建设
  • 通辽网站公司福州优化广告公司
  • 网站怎么样排名自己做网站教学视频教程
  • 专业网站改版网站迁移 域名设置
  • 凡科网网站建设资料织梦做的网站首页幻灯片怎么不能显示
  • 如何做网站海报wordpress加载速度太慢