拦截器绑定未调用拦截器方法

发布于 2021-01-30 17:34:12

我正在使用Java EE 6和Jboss
AS7.1,并尝试使用拦截器绑定(来自jboss网站的示例)。

我有一个InterceptorBinding注解:

@InterceptorBinding
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface GeoRestrictedEquipment {
}

拦截器:

@GeoRestrictedEquipment
@Interceptor
public class GeoRestrictedEquipmentInterceptor {

    @EJB EquipmentDao equipmenttDao;    
    @EJB SecurityService securityService;

    @AroundInvoke
    public Object checker(InvocationContext ctx) throws Exception {
        Integer id = (Integer) ctx.getParameters()[0];
        Equipment equipment = equipmenttDao.findById(id);
        GeoChecker.check(equipment.getSite(), securityService.getUser());

        return ctx.proceed();
    }
}

还有一个豆:

@Stateless
@LocalBean
@SecurityDomain(Realm.NAME)
@RolesAllowed({ Roles.REGISTERED })
public class PumpService implements PumpServiceLocal {

    @Override
    @GeoRestrictedEquipment
    public PumpInfos getPumpInfos(Integer pumpId) {
        /* ... */
    }
}

但是拦截器没有被称为。。。

在编写此代码时将调用拦截器:

@Override
@Interceptors({GeoRestrictedEquipmentInterceptor.class})
public PumpInfos getPumpInfos(Integer pumpId) {
    /* ... */
}

谢谢你的帮助。

关注者
0
被浏览
102
1 个回答
  • 面试哥
    面试哥 2021-01-30
    为面试而生,有面试问题,就找面试哥。

    您是否按照参考示例中的说明启用了拦截器?

    缺省情况下,bean档案没有通过拦截器绑定绑定的已启用拦截器。必须通过将侦听器的类列出在Bean档案的bean.xml文件的元素下来显式启用它。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看