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 ...
随机推荐
- mysql学习笔记--- 字符串函数、日期时间函数
一.常见字符串函数: 1.CHAR_LENGTH 获取长度(字符为单位) 2.FORMAT 格式化 3.INSERT 替换的方式插入 4.INSTR 获取位置 5.LEFT/RIGHT 取左 ...
- Codeforces 264 B. Good Sequences
B. Good Sequences time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- python 创建实例--待完善
今天好好琢磨一下 python 创建实例的先后顺序 一. 就定义一个普通类 Util (默认)继承自 object,覆写 new ,init 方法 class Util(object): def __ ...
- Quartz.net创建windows服务
序言 安装服务 sc create XXService binpath= "XXService.exe" start= auto sc description XXService ...
- u-boot移植(一)---准备工作
一.工具链的制作 1.1 工具 软件工具:crosstool-ng 下载地址:git clone https://github.com/crosstool-ng/crosstool-ng crosst ...
- HTML5中<template>标签的详细介绍
HTML5中<template>标签的详细介绍(图文) 这篇文章主要介绍了HTML5中的template标签,是HTML5入门中的重要知识,需要的朋友可以参考 一.HTML5 templa ...
- 【BARTS计划】【Share_Week1】社交产品思考
Share:每周分享篇有观点和思考的技术文章 社交梦是每个互联网大厂都在做的,好像大家都默认了一种说法:没有社交功能的产品是不完整的,不做社交产品的公司是缺少战略眼光的.但就目前来看,微信的社交霸 ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- ImageNet Classification with Deep Convolutional Neural Networks(译文)转载
ImageNet Classification with Deep Convolutional Neural Networks Alex Krizhevsky, Ilya Sutskever, Geo ...
- 所有Windows7下游戏的全屏问题
Win键+R键,打开运行窗口,输入regedit 回车,这样就打开了注册表编辑器,然后,定位到以下位置:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ ...