拦截器方法未调用拦截器绑定 [英] Interceptor method not called with interceptor binding
问题描述
我有一个InterceptorBinding注释:
@InterceptorBinding
/ pre>
@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];
设备设备= equipmenttDao.findById(id);
GeoChecker.check(equipment.getSite(),securityService.getUser());
return ctx.proceed();
}
}
还有一个bean:
@Stateless
@LocalBean
@SecurityDomain(Realm.NAME)
@RolesAllowed({Roles.REGISTERED})
public class PumpService实现PumpServiceLocal {
@Override
@GeoRestrictedEquipment
public PumpInfos getPumpInfos(Integer pumpId){
/ * ... * /
}
}
但拦截器不被调用...我想念什么从示例中?
当我写下来时,拦截器被调用:
@Override
@Interceptors({GeoRestrictedEquipmentInterceptor.class})
public PumpInfos getPumpInfos(Integer pumpId){
/ * ... * /
}
感谢您的帮助。
解决方案您是否按照引用的示例中所述启用拦截器?
默认情况下,bean归档因为没有启用的拦截器通过
拦截器绑定绑定。拦截器必须由
显式启用,该bean在bean档案的beans.xml
文件的元素下列出其类。
I'm using Java EE 6 & Jboss AS7.1 and try to use interceptor binding (Example from jboss site).
I have an InterceptorBinding annotation:
@InterceptorBinding @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface GeoRestrictedEquipment { }
The interceptor:
@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(); } }
And a bean:
@Stateless @LocalBean @SecurityDomain(Realm.NAME) @RolesAllowed({ Roles.REGISTERED }) public class PumpService implements PumpServiceLocal { @Override @GeoRestrictedEquipment public PumpInfos getPumpInfos(Integer pumpId) { /* ... */ } }
But the interceptor is not called... What do I miss from the example ?
The interceptor is called when I write this:
@Override @Interceptors({GeoRestrictedEquipmentInterceptor.class}) public PumpInfos getPumpInfos(Integer pumpId) { /* ... */ }
Thanks for your help.
解决方案Did you enable your interceptor as described in the referenced example?
By default, a bean archive has no enabled interceptors bound via interceptor bindings. An interceptor must be explicitly enabled by listing its class under the element of the beans.xml file of the bean archive.
这篇关于拦截器方法未调用拦截器绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!