Jersey 2 ApplicationEventListener onEvent() not called

扶醉桌前 提交于 2019-12-12 01:23:22

问题


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>

App configuration:

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

    public MyApplication(){

        register(com.UserLogin.class);

        register(com.MyApplicationEventListener.class);
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/41871655/jersey-2-applicationeventlistener-onevent-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!