From 2cc52338df3c8b67bbbf68016117a04625ab74bf Mon Sep 17 00:00:00 2001 From: abirembaut Date: Thu, 31 Aug 2023 14:08:53 +0200 Subject: [PATCH] feat(session sharing): improve contexts hierarchy * improve Spring contexts hierarchy and in order to have a true hierachy between web context an engine context and not just shared beans * add web package to componentscan for spring session in web context only (not engine) Relates to [DEV-324](https://bonitasoft.atlassian.net/browse/DEV-324) --- .../servlet/EngineInitializerListener.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/EngineInitializerListener.java b/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/EngineInitializerListener.java index d8c3e816db6..90154479c64 100644 --- a/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/EngineInitializerListener.java +++ b/bpm/bonita-api/bonita-server-api-http/src/main/java/org/bonitasoft/engine/api/internal/servlet/EngineInitializerListener.java @@ -21,10 +21,9 @@ import org.bonitasoft.platform.setup.PlatformSetupAccessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.GenericWebApplicationContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; public class EngineInitializerListener implements ServletContextListener { @@ -40,20 +39,25 @@ public void contextInitialized(final ServletContextEvent event) { .createServiceAccessor() .getContext(); - GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext( - new DefaultListableBeanFactory(engineContext), event.getServletContext()); - + AnnotationConfigWebApplicationContext webApplicationContext = initializeWebContext(event, engineContext); webApplicationContext.refresh(); - - //A web application context needs to be referenced in the Servlet context so that servlet and filters beans handled by Spring can use it - event.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, - webApplicationContext); } catch (final Throwable e) { throw new RuntimeException("Error while initializing the Engine", e); } } + protected AnnotationConfigWebApplicationContext initializeWebContext(ServletContextEvent event, + ApplicationContext engineContext) { + AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); + webApplicationContext.setParent(engineContext); + webApplicationContext.setServletContext(event.getServletContext()); + //A web application context needs to be referenced in the Servlet context so that servlet and filters beans handled by Spring web can use it + event.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, + webApplicationContext); + return webApplicationContext; + } + protected EngineInitializer getEngineInitializer() { return new EngineInitializer(); }