泽西岛2 ApplicationEventListener onEvent()未调用 [英] Jersey 2 ApplicationEventListener onEvent() not called

查看:221
本文介绍了泽西岛2 ApplicationEventListener onEvent()未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ApplicationEventListener#onEvent不会被调用.可能出问题了.使用了资源配置类,并且我能够调用API.

The ApplicationEventListener#onEvent is never called. What could be wrong here.The resource config class is used and i am able to call APIs.

<servlet>
    <servlet-name>MyApplication</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.MyApplication</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>MyApplication</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

应用配置:

public class MyApplication extends ResourceConfig{
    @NameBinding
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Secured {}

    public MyApplication(){

        register(com.UserLogin.class);

        register(com.MyApplicationEventListener.class);
    }
}

推荐答案

除非发出请求,否则Jersey不会完全启动,因此永远不会通过启动和停止服务器来调用侦听器.您需要在web.xml中为servlet配置设置<load-on-startup>1</load-on-startup>.服务器启动时,这将导致Jersey完全加载.

Unless you make a request, Jersey will not be fully started, so the listener will never be called by just starting and stopping the server. You need to set <load-on-startup>1</load-on-startup> in the web.xml for the servlet configuration. This will cause Jersey to fully load when the server starts.

这篇关于泽西岛2 ApplicationEventListener onEvent()未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆