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

免费制作证件照的微信小程序seo课程培训机构

免费制作证件照的微信小程序,seo课程培训机构,网站做流量推广的方式,域名怎么拿来做网站Springboot中使用AOP特性非常简单,使用AspectJ注解,然后再配置中开启AspectJ即可。在日常的应用,有时可以将日志记录和异常处理在一个拦截器中统一处理,但有时在项目中无法通过一个拦截器解决所有切面问题,此时&#x…

Springboot中使用AOP特性非常简单,使用@AspectJ注解,然后再配置中开启AspectJ即可。在日常的应用,有时可以将日志记录和异常处理在一个拦截器中统一处理,但有时在项目中无法通过一个拦截器解决所有切面问题,此时,就需要将日志、异常处理等拦截器功能拆分开来,但有一点是相同的,就是在需要时增加一个抽象层次用于拦截。

基础知识

这部分的细节主要是注解的使用,可以参看之后示例。
参考资料
http://www.cnblogs.com/best/p/5736422.html

实践

AOP配置

@Configuration
@EnableAspectJAutoProxy
public class AOPConfig {
}

Log(AOP)实例

@Aspect
@Component
public final class LogInterceptor {private final static int DEFAULT_MAX_LOG_LENGTH = 8192;@Pointcut("execution(*  com.bjork.ws.XXXWSImplForSpring.*(..))")public void serviceMethodPointcut() {}@Pointcut("execution( * com.bjork.ws.agent..*.*(..)) && @annotation(com.bjork.ws.core.AgentOriginalMethod)")public void agentOriginalMethodPointcut() {}@Around("serviceMethodPointcut() || agentOriginalMethodPointcut()")// @Around("agentOriginalMethodPointcut()")public Object Interceptor(ProceedingJoinPoint pjp) throws Throwable {// 获取aop相关信息Signature signature = pjp.getSignature();MethodSignature methodSignature = (MethodSignature) signature;Method targetMethod = methodSignature.getMethod();Class<?> returnType = targetMethod.getReturnType();Object result = null;Logger logger = LoggerFactory.getLogger(pjp.getTarget().getClass());try {// 设置默认返回值result = returnType.newInstance();logger.info(String.format("%s方法调用开始!", targetMethod.getName()));// 约定只有一个参数Object uniqueParameter = pjp.getArgs()[0];logRequest(JsonHelper.serialize(uniqueParameter), logger);result = pjp.proceed();logResponse(JsonHelper.serialize(result), logger);} finally {logger.info(String.format("%s方法调用结束!", targetMethod.getName()));}return result;}protected void logRequest(String requestString, Logger logger) {if (requestString.length() <= DEFAULT_MAX_LOG_LENGTH)logger.info(String.format("请求体为:%s", requestString));}protected void logResponse(String responseString, Logger logger) {if (responseString.length() <= DEFAULT_MAX_LOG_LENGTH)logger.info(String.format("响应体为:%s", responseString));}
}

Exception (AOP)实例

@Aspect
@Component
public final class ServiceInterceptor {@Pointcut("execution(* com.bjork.ws.service..*(..)) "+ "&& @annotation(com.bjork.ws.core.ServiceOpenMethod)")public void serviceMethodPointcut() {}@Around("serviceMethodPointcut()")public GenericResult Interceptor(ProceedingJoinPoint pjp) {// 获取aop相关信息Signature signature = pjp.getSignature();MethodSignature methodSignature = (MethodSignature) signature;Method targetMethod = methodSignature.getMethod();// Class<?> returnType = targetMethod.getReturnType();GenericResult result = new GenericResult();Logger logger = LoggerFactory.getLogger(pjp.getTarget().getClass());try {// 设置默认返回值// result = returnType.newInstance();// 约定只有一个参数Object uniqueParameter = pjp.getArgs()[0];result = (GenericResult) pjp.proceed();} catch (ValidException vex) {result.getResultInfo().setIsSuccessful(false);result.getResultInfo().setCode(vex.getErrorCode());result.getResultInfo().setMessage(vex.getMessage());logger.info(vex.getMessage());} catch (BizException bex) {result.getResultInfo().setIsSuccessful(false);result.getResultInfo().setCode(bex.getErrorCode());result.getResultInfo().setMessage(bex.getMessage());logger.warn(bex.getMessage());} catch (ExternalCallException ecex) {result.getResultInfo().setIsSuccessful(false);result.getResultInfo().setCode(ecex.getErrorCode());result.getResultInfo().setMessage(ecex.getMessage());logger.warn(ecex.getMessage());} catch (Throwable ex) {result.getResultInfo().setIsSuccessful(false);result.getResultInfo().setCode(ExceptionInfo.SYSTEM_EXCEPTION_CODE);result.getResultInfo().setMessage(ExceptionInfo.SYSTEM_EXCEPTION_MESSAGE);logger.error(ex.getMessage(), ex);} finally {}return result;}
}

AutoConfiguration配置

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
//@SpringBootApplication
@ComponentScan("com.xxx.ws")
public class ServiceInitializer extends SpringBootServletInitializer {@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder application) {return application.sources(ServiceInitializer.class);}@Beanpublic LogAspect logAspect() {return new LogAspect();}@Beanpublic ServiceExceptionAspect serviceExceptionAspect() {return new ServiceExceptionAspect();}
}

转载于:https://www.cnblogs.com/xiong2ge/p/springaop_inaction.html

http://www.wooajung.com/news/35309.html

相关文章:

  • 网站建设基本流程是什么seo推广效果
  • 全国物流网站百度搜索最多的关键词
  • 网站怎么放到服务器西安seo服务培训
  • 商务网站建设与维护 ppt最经典最常用的网站推广方式
  • 宝山网站建设 网站外包湖南正规seo优化报价
  • 细胞医疗 网站模版深度搜索
  • 建设信用卡在网站挂失块吗网络推广是指什么
  • 这样做的网站微博营销
  • 手机端网站开发教程临沂百度代理公司有几个
  • 抓好党建网站联盟建设专业seo网络推广
  • 做淘宝有没有店小秘类型的网站网店怎么运营和推广
  • 岳阳做网站 公司电话怎样做网站推广
  • 网站建设公司需要具备销售平台有哪些
  • 东莞网站关键排名优秀营销软文100篇
  • 自己做网站 需要会什么6百度在线入口
  • 网站怎样优化关键词好十大免费cms建站系统介绍
  • phpstudy做正式网站获客
  • 网站摄影设计西安百度代运营
  • 云南住房建设厅网站制作网页代码大全
  • 做采集网站难不关键词优化步骤简短
  • 深圳建设网站费用明细推广app赚钱的平台
  • 优秀平面设计网站公关
  • 企业展示建设网站营销型公司网站建设
  • 比较好的网页设计网站怎么接广告赚钱
  • 万网域名管理控制台百度竞价是seo还是sem
  • 新乡专业做淘宝网站2023搜索最多的关键词
  • 山西两学一做登录网站百度推广客户端怎么登陆
  • 用KEGG网站做通路富集分析热门关键词
  • 做网站需要的合同温州seo结算
  • 企业网站排名优化价格刷seo排名