`

bboss aop 实践(5) 拦截器(Interceptor)

阅读更多

bboss项目下载列表 在sourceforge访问地址为:
https://sourceforge.net/project/showfiles.php?group_id=238653 

bboss aop框架中,可以为业务组件配置1到多个拦截器(Interceptor)。这些拦截器必须实现com.frameworkset.proxy.Interceptor接口。拦截器可以对执行方法的4个时间点进行拦截:

l         执行前

l         执行后

l         抛出异常时

l         方法finally

 

这些点分别对应com.frameworkset.proxy.Interceptor接口提供的4个方法:

    public void before(Method method,Object[] args) throws Throwable;

   

    public void after(Method method,Object[] args) throws Throwable;

  

    public void afterThrowing(Method method,Object[] args,Throwable throwable) throws Throwable;

   

    public void afterFinally(Method method,Object[] args) throws Throwable;

 

通过实现上述4个方法,bboss aop框架就可以方便地实施对业务组件方法的拦截功能。目前系统缺省提供了一个数据库事务管理拦截器:

com.chinacreator.spi.interceptor.TransactionInterceptor

用来实现bboss persistent框架的声明式事务管理功能,参考博客文章《bboss persistent事务管理介绍》。

 

下面举例说明拦截器的定义、配置和使用。

 

定义业务组件和拦截器

l         定义拦截器如下:

**

 * 方法拦截器

 *

 * <p>Title: Insterceptor.java</p>

 *

 * <p>Description: </p>

 *

 * <p>Copyright: Copyright (c) 2007</p>

 *

 * <p>bboss workgroup</p>

 * @Date Sep 5, 2008 4:43:47 PM

 * @author biaoping.yin

 * @version 1.0

 */

public class Insterceptor implements Interceptor {

 

    public void after(Method method, Object[] args) throws Throwable {

       System.out.println("Insterceptor.after(" + method.getName() + ", Object[] args)");

 

    }

 

    public void afterFinally(Method method, Object[] args) throws Throwable {

       System.out.println("Insterceptor.afterFinally(" + method.getName() + ", Object[] args)");

    }

 

    public void afterThrowing(Method method, Object[] args, Throwable throwable)

           throws Throwable {

       System.out.println("Insterceptor.afterThrowing(" + method.getName() + ", Object[] args, Throwable throwable)");

 

    }

 

    public void before(Method method, Object[] args) throws Throwable {

       System.out.println("Insterceptor.before(" + method.getName() + ", Object[] args)");

    }

}

 

l         定义的业务组件接口如下:

package com.chinacreator.spi.interceptor;

 

import com.chinacreator.spi.constructor.ConstructorInf;

 

public interface AI {

    public void testInterceptorsBeforeafterWithTX() throws Exception;

    public void testInterceptorsBeforeAfter() throws Exception;

    public void testInterceptorsBeforeThrowing() throws Exception;

    public void testInterceptorsBeforeThrowingWithTX() throws Exception;

    public void setConst(ConstructorInf inf)

    ;

 

}

 

l         业务组件实现如下:

 

public class A implements AI{

 

    public void testInterceptorsBeforeAfter() throws Exception {

//     System.out.println("testInterceptorsBeforeAfter()");

    }

 

    public void testInterceptorsBeforeThrowing() throws Exception {

//     System.out.println("testInterceptorsBeforeThrowing()");

       throw new Exception("testInterceptorsBeforeThrowing");

      

    }

 

    public void testInterceptorsBeforeThrowingWithTX() throws Exception {

      

//     System.out.println("testInterceptorsBeforeThrowingWithTX()");

       throw new Exception("testInterceptorsBeforeThrowingWithTX");

    }

 

    public void testInterceptorsBeforeafterWithTX() throws Exception {

//     System.out.println("testInterceptorsBeforeafterWithTX()");

    }

 

    public void setConst(ConstructorInf inf) {

       // TODO Auto-generated method stub

      

    }

}

 

配置业务组件和拦截器:

在包com.chinacreator.spi.interceptor下建立文件

simplemanager-interceptor.xml

 

1
0
分享到:
评论

相关推荐

    bboss-aop.jar

    官方版本,亲测可用

    bboss mvcdemo 下载地址

    - 扩展与自定义:指导如何根据需求扩展BBoss MVCDemo,包括自定义拦截器、过滤器等。 总的来说,BBoss MVCDemo是一个全面的开发框架,涵盖了从基础到高级的企业级应用开发各个方面。通过阅读“bboss mvc开发手册....

    bboss-aop-test.jar

    官方版本,亲测可用

    bboss 安全认证过滤器功能介绍

    SYSAuthenticateFilter就是BBoss框架中专门用于安全认证的过滤器,它负责拦截请求,检查用户是否已经登录并拥有访问特定资源的权限。 首先,我们来看一下`SYSAuthenticateFilter.java`这个文件。作为过滤器的实现类...

    Bboss国际化实践.ppt

    【Bboss国际化实践】主要涉及了软件系统的全球化适应性改造,以便支持多语言环境。以下是对这个主题的详细解析: 1. **界面元素国际化**: - 界面文字:所有用户可见的文字都需要进行翻译,确保不同语言环境下的...

    bboss会话共享培训文档

    开发者需要将原来的容器session监听器迁移到bboss会话共享实现。对于修改session中的对象数据,必须调用session.setAttribute方法将对象数据更新到MongoDB中,从而实现数据的共享。 bboss会话共享还提供了两种模式...

    springboot整合bboss es增删改查测试demo代码

    本实例是一个基于bboss es spring boot starter的demo maven工程,可供spring boot项目集成bboss elasticsearch rest client参考 展示了通过spring boot管理单集群功能和管理多集群功能 单集群测试用例:...

    企业级J2EE开源框架bboss

    BBoss(全称为bbossgroups)是一个专为企业级J2EE应用设计的开源框架,它为Java开发者提供了一系列强大的工具和服务,以简化Web应用程序的开发过程。该框架旨在提高开发效率,降低维护成本,同时保持高度的灵活性和...

    bboss-elasticsearch开发环境搭建和开发入门视频教程.

    5. **配置BBoss**: 根据项目需求,配置 BBoss 的连接参数,如集群地址、端口等。 **四、开发入门** 1. **创建索引**: 使用 BBoss 提供的 API 创建索引,指定映射(Mapping)以便对数据类型进行定义。 2. **插入数据...

    bboss+es基本操作示例.zip

    **bboss+es基本操作示例** ...总之,bboss+es基本操作示例是学习和实践Elasticsearch与Java集成的优秀资源,通过这个示例,开发者可以快速掌握bboss框架下的DSL操作,为实际项目开发打下坚实基础。

    springboot集成ElasticsearchBboss调用Elasticsearch.md

    springboot集成ElasticsearchBboss调用Elasticsearch的案例分享

    bboss elasticsearch-5.7.8.rar

    5. `commons-collections-3.2.1.jar`:Apache Commons Collections是Java集合框架的扩展,包含各种实用的集合类和算法,可以增强Elasticsearch数据处理的灵活性。 6. `bboss-velocity-5.5.0.jar`:Velocity是Apache...

    由 bboss 开源的数据采集&流批一体化工具,提供数据采集、数据清洗转换处理和数据入库以及数据指标统计计算流批一体化处理功能

    **bboss-datatran** 是一个由 **bboss** 社区开源的高效数据处理工具,专注于数据采集、数据清洗转换以及数据入库等任务。它实现了流批一体化的数据处理能力,使得用户能够灵活地应对实时和批量的数据处理场景。在...

    bboss-db-elasticsearch-tool-master_java_

    【bboss-db-elasticsearch-tool-master_java_】是一个Java ORM(对象关系映射)框架,它在功能上超越了MyBatis,提供了对多种数据库的广泛支持,包括MySQL、Oracle、PostgreSQL、SQLServer、DB2、DM以及MongoDB。...

    bboss-soa.jar

    官方版本,亲测可用

    bboss ioc配置文件中使用外部属性文件介绍

    BBoss是一个轻量级的企业级应用开发框架,提供了IOC(Inversion of Control)功能,使得对象之间的依赖关系可以通过配置文件进行管理。本文将详细介绍如何在BBoss的IOC配置文件中引用外部属性文件,以便更好地管理和...

    bboss persistent 1.0.2中方便地实现大字段(clob,blob)的处理

    5. **工具支持**:BBoss Persistent作为一个工具,提供了友好的API和示例,使得开发者能够更方便地与数据库交互,尤其是在处理大字段时。通过学习相关文档和博客(如提供的链接),开发者可以快速上手并掌握其使用...

    Elasticsearch rest client bboss介绍-Elastic2018中国开发者大会演讲稿.pptx

    Elasticsearch rest client bboss介绍-Elastic2018中国开发者大会演讲稿

Global site tag (gtag.js) - Google Analytics