ServletContextInitializedEvent can't works in Portal block

Hi,

I need to register custom filter , but the ServletContextInitializedEvent seems that can’t be trigger.

Following is my testing code:
image

The initializeHttpServlet method never be called,
The onstructor method has be called.

And the the same approach works fine in web block.

Am i missing some thing?

Hello @lugreen

Make sure that your component is located in package that is included into Spring component scan. It seems that the component is not initialized at all

Regards,
Daniil

Hi Daniil,

Thanks for your quickly reply.

I can confirm this, as I said, the constructor of the WebInitializer class has been called, and the component is in the scan package indeed .

By step by step debugger,i found that the initializing of WebInitializer is after the trigger of ServletContextInitializedEvent.

And i created a project for reproducing the issue.

eventtest.7z (102.4 KB)

Hi,

Is this a issue?

I’ve checked the project you shared.

To fix the problem place the bean in another package (for example, com.company.eventtest.portal.sys) and define component scan in the portal-spring.xml file.

Please consider sample project:

portal-context-init-evt.zip (310.6 KB)

Regards,
Daniil

1 Like

Hi Daniil,

Thanks for your sample project.

The root cause for my problem is my Bean is not loaded by the root spring context,is it right?

Regards,
Ray

The bean was loading in Dispatcher Spring context, but event is published in another context.

Hi Daniil,

Thanks for your explain.

Regard,
Ray