gpt4 book ai didi

java - 未使用拦截器绑定(bind)调用拦截器方法

转载 作者:搜寻专家 更新时间:2023-10-30 21:00:21 25 4
gpt4 key购买 nike

我正在使用 Java EE 6 和 Jboss AS7.1 并尝试使用拦截器绑定(bind) ( Example from jboss site )。

我有一个 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();
}
}

还有一个 bean :

@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) {
/* ... */
}

感谢您的帮助。

最佳答案

根据文档还有另一种方法而不是使用 beans.xml:

You do not need to specify the interceptor in the beans.xml file when you use the @Priority annotation.

@Logged
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public class LoggedInterceptor implements Serializable { ... }

而且有效。

关于java - 未使用拦截器绑定(bind)调用拦截器方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12076586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com