lugreen
(Ray Lv)
July 29, 2019, 9:31am
#1
Hi,
I need to register custom filter , but the ServletContextInitializedEvent seems that can’t be trigger.
Following is my testing code:
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?
tsarev
(Daniil Tsaryov)
July 29, 2019, 11:19am
#3
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
lugreen
(Ray Lv)
July 30, 2019, 1:11am
#5
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)
tsarev
(Daniil Tsaryov)
August 5, 2019, 5:54am
#7
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
lugreen
(Ray Lv)
August 5, 2019, 8:31am
#8
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
tsarev
(Daniil Tsaryov)
August 5, 2019, 8:58am
#9
The bean was loading in Dispatcher Spring context, but event is published in another context.