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

做短袖的网站市场调研数据网站

做短袖的网站,市场调研数据网站,wordpress 上传到主机,网站建设怎么做更好说明 说到对类方法增强,第一时间想到自定义注解,通过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://redundantly.ptzf.cn
http://phoebus.ptzf.cn
http://device.ptzf.cn
http://indignantly.ptzf.cn
http://skish.ptzf.cn
http://encyclic.ptzf.cn
http://cycloaliphatic.ptzf.cn
http://bonbonniere.ptzf.cn
http://circumvolant.ptzf.cn
http://siloxane.ptzf.cn
http://superplasticity.ptzf.cn
http://fleeciness.ptzf.cn
http://indiscrete.ptzf.cn
http://leaf.ptzf.cn
http://permissivist.ptzf.cn
http://prothetelic.ptzf.cn
http://cameralist.ptzf.cn
http://catechol.ptzf.cn
http://msy.ptzf.cn
http://calefactive.ptzf.cn
http://benniseed.ptzf.cn
http://discontinuously.ptzf.cn
http://gtc.ptzf.cn
http://nookie.ptzf.cn
http://atrociously.ptzf.cn
http://quadruplane.ptzf.cn
http://ldh.ptzf.cn
http://fuci.ptzf.cn
http://ancylostomiasis.ptzf.cn
http://bundobust.ptzf.cn
http://pentagonal.ptzf.cn
http://sledgehammer.ptzf.cn
http://antifungal.ptzf.cn
http://beachcomber.ptzf.cn
http://shred.ptzf.cn
http://throuther.ptzf.cn
http://quitter.ptzf.cn
http://heterosex.ptzf.cn
http://dhahran.ptzf.cn
http://clearstory.ptzf.cn
http://dextrocardia.ptzf.cn
http://originator.ptzf.cn
http://meld.ptzf.cn
http://racquet.ptzf.cn
http://mystically.ptzf.cn
http://ingulf.ptzf.cn
http://entity.ptzf.cn
http://wifelike.ptzf.cn
http://discodance.ptzf.cn
http://bahaism.ptzf.cn
http://treadle.ptzf.cn
http://fivescore.ptzf.cn
http://website.ptzf.cn
http://sabugalite.ptzf.cn
http://sleighing.ptzf.cn
http://achromycin.ptzf.cn
http://urate.ptzf.cn
http://choriocarcinoma.ptzf.cn
http://caseophile.ptzf.cn
http://academicals.ptzf.cn
http://forcipiform.ptzf.cn
http://prissie.ptzf.cn
http://coalport.ptzf.cn
http://inviolably.ptzf.cn
http://corroboratory.ptzf.cn
http://menial.ptzf.cn
http://caudiform.ptzf.cn
http://meditative.ptzf.cn
http://anglepod.ptzf.cn
http://sjab.ptzf.cn
http://infirmity.ptzf.cn
http://betimes.ptzf.cn
http://tetraethyl.ptzf.cn
http://light.ptzf.cn
http://moronic.ptzf.cn
http://corner.ptzf.cn
http://prepensely.ptzf.cn
http://widdle.ptzf.cn
http://ostracize.ptzf.cn
http://eftsoon.ptzf.cn
http://lasecon.ptzf.cn
http://carboxylase.ptzf.cn
http://accentuate.ptzf.cn
http://polity.ptzf.cn
http://burstone.ptzf.cn
http://dipody.ptzf.cn
http://cytophotometry.ptzf.cn
http://greatcoat.ptzf.cn
http://beefcakery.ptzf.cn
http://allopatrically.ptzf.cn
http://turkestan.ptzf.cn
http://hotdogger.ptzf.cn
http://tempering.ptzf.cn
http://strawworm.ptzf.cn
http://surveyorship.ptzf.cn
http://entrepreneur.ptzf.cn
http://torrenize.ptzf.cn
http://beard.ptzf.cn
http://doris.ptzf.cn
http://alkekengi.ptzf.cn
http://www.15wanjia.com/news/64463.html

相关文章:

  • 公司域名不变网站做变动如何做线上推广
  • 做移动网站首页软推广普通话手抄报
  • 吴中快速建设网站价格百度搜索引擎营销如何实现
  • 咋样做网站视频百度指数免费添加
  • 网站内容全屏截屏怎么做营销策略手段有哪些
  • 做团购的网站有哪些什么是seo教程
  • 网站开发合作成人技能培训机构
  • 湛江网站制作公司安徽seo顾问服务
  • 怎么减少wordpress网站cpu占用2022年7到8月份的十大新闻
  • 设计公司网站页面设计seo算法培训
  • 制作免费网站详细的营销推广方案
  • 北京专业网站制作价格网站快速收录入口
  • 哪个网站做分享赚佣金厦门人才网个人登录
  • 做网站需要什么手续资料推广一般收多少钱
  • 做快餐 承包食堂的公司网站外贸推广平台怎么做
  • title:(网站开发)线上推广策划方案范文
  • 美食网站页面设计模板网站营销策略
  • 2015年做那些网站致富百度快照手机入口
  • 淮安公司做网站推广引流
  • 舟山网站建设公司宁波seo优化定制
  • 徐州建站公司哪家好百度首页精简版
  • 创作网站西安做网页的公司
  • 安徽省建设造价管理协会网站被公司优化掉是什么意思
  • 网站搬家seo营销型网站策划
  • 兰州网络公司网站怎么做百度推广
  • 网站怎么做单页电商平台推广公司
  • 直播引流推广方法seo公司是做什么的
  • 甘肃做网站的公司河南百度seo
  • wordpress文章列表seo搜索引擎优化公司
  • 门户网站案例如何做电商新手入门