SpringBank 开发日志 一种简单的拦截器设计实现
2017-07-24 20:03
375 查看
当交易由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; } }
相关文章推荐
- 一种Java日志系统框架的设计与实现
- 中国象棋程序的设计与实现(七)--心得体会和开发日志
- 中国象棋程序的设计与实现(七)--心得体会和开发日志
- 使用Spring设计和实现Web应用程序 开发指引(一)
- android网游开发之socket的简单设计和实现
- 一种日志结构文件系统的设计与实现(二)
- 使用Spring设计和实现Web应用程序 开发指引(四)
- android网游开发之socket的简单设计和实现
- 使用Spring设计和实现Web应用程序 开发指引(二)
- 毕业设计开发日志,基于ARM的嵌入式人脸识别系统的设计与实现
- 从头认识Spring-3.1 简单的AOP日志实现-某方法之前的前后记录日志
- 一种简单的嵌入式字库设计及其实现原理
- Linux下一个简单的日志系统的设计及其C代码实现
- 使用Spring设计和实现Web应用程序 开发指引(三)
- PC Camera 开发日志(六)------ 一种可换皮肤的对话框实现
- android网游开发之socket的简单设计和实现
- Linux下一个简单的日志系统的设计及其C代码实现
- 一种日志结构文件系统的设计与实现(三)
- 中国象棋程序的设计与实现(七)--心得体会和开发日志
- 一种面向作业流(工作流)的轻量级可复用的异步流水开发框架JobFlow的设计与实现