SpringBank 开发日志 一种简单的拦截器设计实现
当交易由Action进入Service之前,需要根据不同的Service实际负责业务的不同,真正执行Service的业务逻辑之前,做一些检查工作。这样的拦截器应该是基于配置的,与Service关联起来的。
/**
* @author wangxin
* @contact 408657544@qq.com
* @date Jul 22, 2017
* @Description: 所有TransactionController的抽象父类,主要作用为以一种低耦合的方式调用Service
*/
public abstract class BaseController {
private final Logger log = LoggerFactory.getLogger(getClass());
@SuppressWarnings("rawtypes")
public Map callService(String service,Map request) {
Class<?> clazz;
try {
clazz = Class.forName("com.springbank.service.service." + service);
Method method = clazz.getMethod("execute", Map.class);
Service bean = (Service) ApplicationContextUtil.getApplicationContext().getBean(clazz);
//先执行拦截器栈
List<Interceptor> interceptorList = (List<Interceptor>) clazz.getMethod("getInterceptorList", null).invoke(bean, null);
for (Interceptor interceptor : interceptorList) {
interceptor.process();
}
//反射非静态方法,需要把第一个参数设置为对象
return (Map)method.invoke(bean, request);
} catch (ClassNotFoundException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
} catch (NoSuchMethodException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
} catch (SecurityException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
} catch (IllegalAccessException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
} catch (IllegalArgumentException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
} catch (InvocationTargetException e) {
ExceptionHandler.throwExcep(ExpceptionMapping.SYSTEMERR, e);
}
return null;
}
}
SpringBank 开发日志 一种简单的拦截器设计实现的更多相关文章
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- AOP框架Dora.Interception 3.0 [3]: 拦截器设计
对于所有的AOP框架来说,多个拦截器最终会应用到某个方法上.这些拦截器按照指定的顺序构成一个管道,管道的另一端就是针对目标方法的调用.从设计角度来将,拦截器和中间件本质是一样的,那么我们可以按照类似的 ...
- 04springMVC结构,mvc模式,spring-mvc流程,spring-mvc的第一个例子,三种handlerMapping,几种控制器,springmvc基于注解的开发,文件上传,拦截器,s
1. Spring-mvc介绍 1.1市面上流行的框架 Struts2(比较多) Springmvc(比较多而且属于上升的趋势) Struts1(即将被淘汰) 其他 1.2 spring-mv ...
- SpringBank 开发日志 重新设计Action调用Service的参数传递 使用泛型解决类型转换问题
之前想的比较简单,请求到达controller的时候,传给action的参数没有经过任何封装,就是一个Map.然后action再调用service的时候,传递的参数也是map @Controller ...
- springmvc实现简单的拦截器
SpringMVC 中的Interceptor 拦截请求是通过HandlerInterceptor 来实现的.在SpringMVC 中定义一个Interceptor 非常简单,主要有两种方式,第一种方 ...
- 配置简单的拦截器java中
springMVC.xml文件中==== <!-- 拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:map ...
- springbank 开发日志 springbank是如何注册handler的
这要从DefaultAnnotationHandlerMapping这个类说起,该类被@Component注释,该类被Spring IOC容器实例化之后,将会执行其initApplicationCon ...
- SpringBank 开发日志 使用maven构建dubbo服务的可执行jar包
写这篇日志的时候,我已经完成了这个目标,并且中间经历了一次面试.现在回过头看,已经觉得印象不那么深刻了,果然还是一边思考,一边记录这样最好.但我还是严格要求自己,从新做了梳理,对相关配置进行了整理和说 ...
- SpringBank 开发日志 Mybatis 使用redis 作为二级缓存时,无法通过cacheEnabled=false 将其关闭
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
随机推荐
- Catfish CMS漏洞集合
转自https://larryxi.github.io/ 0x00 背景 版本:V 4.2.35 官网下载:http://www.catfish-cms.com/page/4.html 文章内容仅作学 ...
- numpy笔记—np.squeeze用法
import numpy as np x = np.array([[[0], [1], [2]]]) print(x.shape) d = np.squeeze(x) # 从数组的形状中删除单维条目, ...
- DCNN models
r egion based RNN Fast RCNN Faster RCNN F-RCN Faster RCNN the first five layers is same as the ZF ne ...
- fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory(转)
fatal error C1083: 无法打开包括文件: “SDKDDKVer.h”: No such file or directory 解决办法:(Vs2013中) 项目--右键--属性--配置属 ...
- 个人经验~mysql故障处理思路
一 简介:个人经验总结 二 思路: 从整体上再进行梳理 三 linux角度 1 硬件是否有问题 常见主板 raid卡 和raid磁盘组 2 综合指标 负载 uptime : 1min 5min ...
- 公共模块定义/草案(Common Module Definition / draft - CMD草案)
This specification addresses how modules should be written in order to be interoperable in browser-b ...
- ubuntu + usb转RS232驱动
1. 购买USB转串RS232/485/422 如果你的电脑有串口的话,就不用买啦,我的台式机有串口,把USB转串的线插上之后,unbuntu就不支持了.(自己有嘛) 就是输入 ls /dev/tt ...
- Linux内核调试 - 一般人儿我都不告诉他(一)【转】
转自:http://www.cnblogs.com/armlinux/archive/2011/04/14/2396821.html 悄悄地进入Linux内核调试(一) 本文基址:http://blo ...
- 【转】htop使用详解--史上最强(没有之一)
在管理进程时通常要借助一些工具,比较常用的就是ps和top了:不过CentOS还为我们提供了一个更加强大的工具htop,下面就来了解一下此工具的使用方法.一.安装htop htop工具在epel源中提 ...
- centos 6.5内核编译步骤及配置详解
1.准备并加压内核安装包:linux-3.13.2.tar.xz # tar xf linux-3.13.2.tar.xz -C /usr/src # cd /usr/src/ # ln -sv li ...