我正在使用 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) {
/* ... */
}
谢谢你的帮助。