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 ...
随机推荐
- js正则表达式【原】
js正则表达式 http://www.w3school.com.cn/js/js_obj_regexp.asp js常用正则表达式 我的自测样例 <HTML> <HEAD> & ...
- golang数组声明
格式 初始化数组 {}中的元素数不能大于[]中的数字,并且长度在初始化后不能改变,定义数组时需指定长度 ... var arrName [num]type = [num]type{value, val ...
- python 创建实例--待完善
今天好好琢磨一下 python 创建实例的先后顺序 一. 就定义一个普通类 Util (默认)继承自 object,覆写 new ,init 方法 class Util(object): def __ ...
- C# Winform中慎用Application.DoEvents
private void Add() { ; i < ; i++) { Button button = new Button(); button.Width = ; button.Height ...
- luogu P1762 偶数
打表找规律吼题哇 首先打出\(1-1000\)内的答案的表 0 0 1 1 4 6 9 9 16 ... 448363 ~~有个**规律啊qwq~~ 然后想到用\(\frac{n(n+1)}{2}\) ...
- static extern
/*主程序在a.c*/ //a.c #include <stdio.h> #include "b.h" main(){ printf ("%d\n" ...
- Android判断当前是否在主线程
Android开发中, 有时需要判断当前线程到底是主线程, 还是子线程, 例如: 我们在自定义View时, 想要让View重绘, 需要先判断当前线程到底是不是主线程, 然后根据判断结果来决定到底是调用 ...
- ubuntu下安装搜狗输入法以及出现不能输入中文的解决办法
1. 官网下载安装包 http://pinyin.sogou.com/linux/?r=pinyin 下载你需要的版本,这里选择64位版. 2. 进入软件中心安装 3. 修改ibus为fcitx im ...
- SpringBoot集成Dubbo
(1).新建一个普通Maven项目,用于存放一些公共服务接口及公共的Bean等. 项目: 公共Bean: package cn.coreqi.entities; import java.io.Seri ...
- UART中的硬件流控RTS与CTS DTR DSR DTE设备和DCE设备【转】
中低端路由器上使用disp interface 查看相应串口状态信息,其中DCD.DTR.DSR.RTS及CTS等五个状态指示分别代表什么意思? DCD ( Data Carrier Detect 数 ...