Ошибка CDI для перехватчика в Websphere 8.5

Я только что включил CDI в Websphere 8.5.5 и добавил перехватчики.

В файле beans.xml

<?xml version="1.0"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"
xsi:schemeLocation="http://java.sun.com/xml/ns/javaee http://
java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
    <class>com.example.jaxrs.SecurityChecked</class>
</interceptors>
</beans>

Аннотация SecurityChecked

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.interceptor.InterceptorBinding;

@Inherited
@InterceptorBinding
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface SecurityChecked {
}

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@Interceptor
@SecurityChecked
public class SecurityCheckInterceptor {

 @AroundInvoke
 public Object checkSecurity(InvocationContext context) throws Exception {
    /*
     * check the parameters or do a generic security check before invoking
     * the original method
     */
    Object[] params = context.getParameters();

    /* if security validation fails, you can throw an exception */
    System.out.println("in securitycheck interceptor");

    /* invoke the proceed() method to call the original method */
    Object ret = context.proceed();

    /* perform any post method call work */
    return ret;
}
}

В классе JAX-RS, как показано ниже

@GET
@com.example.jaxrs.SecurityChecked
public String checkInterceptor(String hello) {
    return "Hello world!";
}

Когда я развертываю EAR, я получаю ошибку ниже.

WebContainerL I WebContainerLifecycle startПриложение OpenWebBeans Container запускается...

[15/10/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer deploy org.apache.webbeans.exception.WebBeansConfigurationException: данный класс: интерфейс com.example.jaxrs.SecurityChecked не является классом-перехватчиком

Любые предложения, что может быть причиной этой ошибки?


person user923499    schedule 15.10.2014    source источник


Ответы (1)


В сообщении об ошибке все сказано. SecurityChecked — это не перехватчик, а просто аннотация, используемая для привязки перехватчика. Перехватчиком является SecurityCheckInterceptor, поэтому ваш файл beans.xml должен содержать:

<interceptors>
    <class>com.example.jaxrs.SecurityCheckInterceptor</class>
</interceptors>

С уважением,
Светлин

person Svetlin Zarev    schedule 15.10.2014
comment
Ой! мой плохой, позвольте мне исправить это. Спасибо! - person user923499; 15.10.2014
comment
Подумайте о том, чтобы принять мой ответ, если он решит проблему :) - person Svetlin Zarev; 15.10.2014