[英]Interceptor method not called with interceptor binding
我正在使用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) {
/* ... */
}
謝謝你的幫助。
根據文檔,還有另一種方法,而不是使用beans.xml:
使用@Priority批注時,無需在beans.xml文件中指定攔截器。
@Logged
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public class LoggedInterceptor implements Serializable { ... }
它有效。
您是否按照引用示例中的描述啟用了攔截器?
默認情況下,bean歸檔文件沒有通過攔截器綁定綁定的已啟用攔截器。 必須通過在bean歸檔文件的beans.xml文件的元素下列出其類來顯式啟用攔截器。
您可以使用任何優先級值= Priority.Application默認為2000。
例如=
@Interceptor
@Loggable
@Priority(100)
public class FileLogger {}
優先類型:
您可以管理攔截器的主要負載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.