简体   繁体   English

Websphere 8.5上的拦截器的CDI错误

[英]CDI Error for interceptor on Websphere 8.5

I have just enabled CDI on Websphere 8.5.5 and added interceptors 我刚刚在Websphere 8.5.5上启用了CDI并添加了拦截器

In beans.xml file 在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 annotation 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;
}
}

In JAX-RS class as below 在如下的JAX-RS类中

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

When i deploy EAR, i get below error. 当我部署EAR时,出现以下错误。

WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting... WebContainerL I WebContainerLifecycle startApplication OpenWebBeans容器正在启动...

[10/15/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer deploy org.apache.webbeans.exception.WebBeansConfigurationException: Given class : interface com.example.jaxrs.SecurityChecked is not a interceptor class [10/15/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer部署org.apache.webbeans.exception.WebBeansConfigurationException:给定的类:接口com.example.jaxrs.SecurityChecked不是拦截器类

Any suggestions what would be the cause of this error? 有什么建议会导致此错误吗?

The error message says it all. 错误消息说明了一切。 SecurityChecked is not an interceptor, but a mere annotation used for interceptor binding.The interceptor is SecurityCheckInterceptor so your beans.xml should contain: SecurityChecked不是拦截器,而仅仅是用于拦截器绑定的注释 。拦截器是SecurityCheckInterceptor因此您的beans.xml应该包含:

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

Regards, 问候,
Svetlin 斯韦特林

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM