【问题标题】:CDI Error for interceptor on Websphere 8.5Websphere 8.5 上拦截器的 CDI 错误
【发布时间】:2014-10-15 19:02:33
【问题描述】:

我刚刚在 Websphere 8.5.5 上启用了 CDI 并添加了拦截器

在 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 startApplication OpenWebBeans 容器正在启动...

[10/15/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer deploy org.apache.webbeans.exception.WebBeansConfigurationException:给定类:接口 com.example.jaxrs.SecurityChecked 不是拦截器类

有什么建议会导致此错误吗?

【问题讨论】:

    标签: jakarta-ee websphere cdi java-ee-6 websphere-8


    【解决方案1】:

    错误消息说明了一切。 SecurityChecked 不是拦截器,只是用于拦截器绑定的注解。拦截器是SecurityCheckInterceptor,因此您的 beans.xml 应包含:

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

    问候,
    斯维特林

    【讨论】:

    • 哎呀!我的错,让我解决这个问题。谢谢!
    • 如果能解决问题,请考虑接受我的回答 :)
    猜你喜欢
    • 2020-06-17
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多