Jersey 2 ApplicationEventListener onEvent () not called

ApplicationEventListener#onEventnever called. What could be wrong here. The resource configuration class is used, and I can call the 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>

Application Configuration:

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

    public MyApplication(){

        register(com.UserLogin.class);

        register(com.MyApplicationEventListener.class);
    }
}
0
source share
1 answer

If you do not make a request, Jersey will not be fully started, so the listener will never be called simply by starting and stopping the server. You need to install <load-on-startup>1</load-on-startup>in web.xml to configure the servlet. This will result in a fully loaded jersey at server startup.

0
source

Source: https://habr.com/ru/post/1608286/


All Articles