Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 拦截器';s@AroundInvoke未触发_Java_Aop_Interceptor - Fatal编程技术网

Java 拦截器';s@AroundInvoke未触发

Java 拦截器';s@AroundInvoke未触发,java,aop,interceptor,Java,Aop,Interceptor,我正在研究拦截器在java中的工作原理。我正在使用Netbeans IDE,刚刚创建了一个名为拦截器的新项目 我创建了一个名为“logged”的注释 然后我创建了一个类“LoggedInterceptor” 然后,我刚刚创建了一个类,该类使用日志注释 public class SuperService { @Logged public String deliverService(String uid) { return uid; }

我正在研究拦截器在java中的工作原理。我正在使用Netbeans IDE,刚刚创建了一个名为拦截器的新项目

我创建了一个名为“logged”的注释

然后我创建了一个类“LoggedInterceptor”

然后,我刚刚创建了一个类,该类使用日志注释

public class SuperService 
{
    @Logged
    public String deliverService(String uid) 
    {
        return uid;
    }

    public static void main(String[] args) 
    {
        SuperService ss = new SuperService();
        System.out.println(ss.deliverService("sisi"));
    }
}
什么也没发生。后来我在src/main/resources/META-INF/下添加了一个名为beans.xml的xml文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                           http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    version="1.1"
    bean-discovery-mode="all">
    <interceptors>
        <class>ascompany.interceptors.LoggedInterceptor</class>
    </interceptors>
</beans>

ascompany.interceptors.LoggedInterceptor
但当我调用deliverService方法时,不会调用logMethodEntry方法。我是否缺少其他配置文件?还是别的什么

我已经尝试将@Priority注释添加到LoggedInterceptor,但没有任何更改

编辑:


正如@Luciano van der Veekens所说,我在LoggedInterceptor中添加了logget注释,但没有任何变化

您忘记了用
@Logged
注释LoggedInterceptor类。这实际上将注释绑定到拦截器

@Logged
@Interceptor
public class LoggedInterceptor implements Serializable {
}
他们在其中一个教程中也这样做


而且它看起来像是一个普通的类。拦截器是一个Java EE概念,只适用于部署在应用服务器上的EJB。

我添加了它……但没有任何改变……还有什么?@MarcoCastano拦截器只适用于部署在应用服务器上的EJBserver@LucianVanDerVeekens好吧,我想我错了…谢谢你的时间…你知道有什么可以执行的吗在以这种方式执行方法之前还是之后?
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                           http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    version="1.1"
    bean-discovery-mode="all">
    <interceptors>
        <class>ascompany.interceptors.LoggedInterceptor</class>
    </interceptors>
</beans>
@Logged
@Interceptor
public class LoggedInterceptor implements Serializable {
}