简体   繁体   English

泽西岛2 ApplicationEventListener onEvent()未调用

[英]Jersey 2 ApplicationEventListener onEvent() not called

The ApplicationEventListener#onEvent is never called. 永远不会调用ApplicationEventListener#onEvent What could be wrong here.The resource config class is used and i am able to call APIs. 这里可能出问题了。使用了资源配置类,并且我能够调用API。

<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>

App configuration: 应用配置:

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

    public MyApplication(){

        register(com.UserLogin.class);

        register(com.MyApplicationEventListener.class);
    }
}

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. 除非您发出请求,否则Jersey不会完全启动,因此永远不会仅通过启动和停止服务器来调用侦听器。 You need to set <load-on-startup>1</load-on-startup> in the web.xml for the servlet configuration. 您需要在web.xml中为servlet配置设置<load-on-startup>1</load-on-startup> This will cause Jersey to fully load when the server starts. 服务器启动时,这将导致Jersey完全加载。

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

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