Hi!
We use some validators which are applied with @Constraint(validatedBy = ... ) These validators use some @Autowired dependencies, which we support by using SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(..) Migrating to Spring boot, we noticed these dependencies end up being 'null'. Further investigation shows that this happens because: - SpringBeanAutowiringSupport relies on ContextLoader.getCurrentWebApplicationContext() - ContextLoader relies on having it's initWebApplicationContext(..) called from ContextLoaderListener.contextInitialized(..) - In Spring Boot ContextLoader is overridden by a private SpringBootContextLoaderListener, which overrides contextInitialized(..) with an empty one (comment: // no-op because the application context is already initialized). - This means initWebApplicationContext is never called, and the whole system doesn't work.
Is this intended behaviour, or broken on accident? Is it possible for it to be fixed? Is there any workaround possible?
Spring Boot 2.5.6, and 2.6.6
Thanks!
Comment From: wilkinsona
ContextLoaderListener is specific to deploying a war file to a standalone container isn't generally applicable in a Spring Boot application. To ensure consistent behaviour across both embedded web servers and war deployment to a standalone container, you should use processInjectionBasedOnServletContext as the WebApplicationContext should consistently be available via the ServletContext.