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

黄页网址大全视频在线观看seo优化要做什么

黄页网址大全视频在线观看,seo优化要做什么,金融企业类网站模板免费下载,网站建设平面要多少分辨率说明 说到对类方法增强,第一时间想到自定义注解,通过aop切面进行实现。这是一种常用做法,但是在某些场景下,如开发公共组件,定义aop切面可能不是最优方案。以后通过原生aop方式,自定义注解,对类…

说明

说到对类方法增强,第一时间想到自定义注解,通过aop切面进行实现。这是一种常用做法,但是在某些场景下,如开发公共组件,定义aop切面可能不是最优方案。以后通过原生aop方式,自定义注解,对类方法进行增强。

实现

自定义注解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CustomStat {
}

自定义切点

/*** 切点(Pointcut),按照规则匹配需要代理的方法*/
@Slf4j
public class CustomPointcut extends StaticMethodMatcherPointcut implements ClassFilter {@Overridepublic boolean matches(Class<?> clazz) {boolean contains = clazz.getName().contains("com.spring.demo.service");if (contains) {log.info("CustomPointcut:{}",clazz.getName());}return contains;}@Overridepublic boolean matches(Method method, Class<?> targetClass) {boolean contains = targetClass.getName().contains("com.spring.demo.service");if (contains) {log.info("CustomPointcut:{}",targetClass.getName());}return contains;}
}

自定义增强器

public class CustomAnnotationAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware, Ordered {private Advice advice;private Pointcut pointcut;private MethodInterceptor methodInterceptor;public CustomAnnotationAdvisor(MethodInterceptor methodInterceptor) {this.methodInterceptor = methodInterceptor;this.advice = buildAdvice();this.pointcut = buildPointcut();}@Overridepublic Pointcut getPointcut() {return this.pointcut;}@Overridepublic Advice getAdvice() {return this.advice;}@Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {if (this.advice instanceof BeanFactoryAware) {((BeanFactoryAware) this.advice).setBeanFactory(beanFactory);}}protected Advice buildAdvice() {return methodInterceptor;}protected Pointcut buildPointcut() {//构建切点Pointcut cpc = new AnnotationMatchingPointcut(CustomStat.class, true);Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(CustomStat.class);return new ComposablePointcut(cpc).union(mpc);}@Overridepublic int getOrder() {return Integer.MAX_VALUE;}
}

其中构造参数中的MethodInterceptor为最终代理拦截器

自定义拦截器

@Slf4j
@Component
public class CustomAnnotationInterceptor implements MethodInterceptor {@Overridepublic Object invoke(MethodInvocation invocation) throws Throwable {//调用的方法和参数//Method method = invocation.getMethod();// Object[] arguments = invocation.getArguments();log.info("start-注解aop拦截器");Object proceed = invocation.proceed();log.info("end-注解aop拦截器");return proceed;}
}

注册增强器

@Component
public class CustomAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware {@Resourceprivate CustomAnnotationInterceptor customAnnotationInterceptor;@Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {setBeforeExistingAdvisors(true);CustomAnnotationAdvisor advisor = new CustomAnnotationAdvisor(customAnnotationInterceptor);advisor.setBeanFactory(beanFactory);this.advisor = advisor;}
}

测试

    @Override@CustomStatpublic void printWork() {System.out.println("WorkServiceImpl1");}

结果

2024-05-21 08:55:26.486  INFO 41351 --- [nio-8081-exec-5] c.s.d.a.CustomAnnotationInterceptor      : start-注解aop拦截器
WorkServiceImpl1
2024-05-21 08:55:26.486  INFO 41351 --- [nio-8081-exec-5] c.s.d.a.CustomAnnotationInterceptor      : end-注解aop拦截器
http://www.hkea.cn/news/548241/

相关文章:

  • html 做网站案例简单网站推广建设
  • 践行新使命忠诚保大庆网站建设线上广告
  • 定制网站建设服务商商家联盟营销方案
  • 集团官网建设公司外贸seo推广公司
  • 佛山新网站制作平台网站诊断工具
  • 做PPT的网站canvawhois查询
  • 营销型网站建设吉林定制化网站建设
  • 个人网上公司注册流程图新站优化案例
  • 做se要明白网站明星百度指数排名
  • 网页微博草稿箱在哪西安seo推广优化
  • 嘉兴微信网站建设谷歌首页
  • 什么网站做海报b站不收费网站
  • 如何自己做个简单网站seo知识点
  • 有哪些做批发的网站有哪些手续百度推广优化是什么意思
  • 用阿里巴巴店铺做公司网站怎么样引擎搜索有哪些
  • 网页制作软件属于什么软件类别简述seo的优化流程
  • 网站建设 公司新闻谷歌排名网站优化
  • 怎样做自己的vip解析网站佛山外贸seo
  • 我的网站在百度搜不到了seo是什么职业做什么的
  • 网站私信界面国外网站seo免费
  • wordpress mysql类惠州网站seo
  • 为什么做网站必须要用域名举出最新的网络营销的案例
  • 电子请柬网站开发百度竞价推广登录入口
  • 网站设计与推广国际时事新闻2022最新
  • 柬埔寨网站开发营销技巧和营销方法
  • 网站建立价格长沙网站外包公司
  • 王建设医生个人网站免费google账号注册入口
  • 免费自建手机网站搜索引擎优化的方法包括
  • 甘肃省建设工程安全质量监督管理局网站官网拉新项目官方一手平台
  • 做电影网站赚钱武汉新闻最新消息