我正在使用Java EE 6 & Jboss AS7.1並嘗試使用攔截器綁定(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();
}
}
而且豆:
@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,但事實上它是...... –
這似乎也是JavaEE7的情況。 –