/** * Register web-specific scopes ("request", "session", "globalSession", "application") * with the given BeanFactory, as used by the WebApplicationContext. * @param beanFactory the BeanFactory to configure * @param sc the ServletContext that we're running within */ public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false)); beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true)); if (sc != null) { ServletContextScope appScope = new ServletContextScope(sc); beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope); // Register as ServletContext attribute, for ContextCleanupListener to detect it. sc.setAttribute(ServletContextScope.class.getName(), appScope); } beanFactory.registerResolvableDependency(ServletRequest.class, new RequestObjectFactory()); beanFactory.registerResolvableDependency(HttpSession.class, new SessionObjectFactory()); beanFactory.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory()); if (jsfPresent) { FacesDependencyRegistrar.registerFacesDependencies(beanFactory); } }
/** * Register web-specific scopes ("request", "session", "globalSession") * with the given BeanFactory, as used by the Portlet ApplicationContext. * @param bf the BeanFactory to configure * @param pc the PortletContext that we're running within */ static void registerPortletApplicationScopes(ConfigurableListableBeanFactory bf, PortletContext pc) { bf.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); bf.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false)); bf.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true)); if (pc != null) { PortletContextScope appScope = new PortletContextScope(pc); bf.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope); // Register as PortletContext attribute, for ContextCleanupListener to detect it. pc.setAttribute(PortletContextScope.class.getName(), appScope); } bf.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory()); bf.registerResolvableDependency(PortletResponse.class, new ResponseObjectFactory()); bf.registerResolvableDependency(PortletSession.class, new SessionObjectFactory()); bf.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory()); }
/** * Register web-specific scopes ("request", "session", "globalSession", "application") * with the given BeanFactory, as used by the WebApplicationContext. * @param beanFactory the BeanFactory to configure * @param sc the ServletContext that we're running within */ public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false)); beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true)); if (sc != null) { ServletContextScope appScope = new ServletContextScope(sc); beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope); // Register as ServletContext attribute, for ContextCleanupListener to detect it. sc.setAttribute(ServletContextScope.class.getName(), appScope); } beanFactory.registerResolvableDependency(ServletRequest.class, new RequestObjectFactory()); beanFactory.registerResolvableDependency(ServletResponse.class, new ResponseObjectFactory()); beanFactory.registerResolvableDependency(HttpSession.class, new SessionObjectFactory()); beanFactory.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory()); if (jsfPresent) { FacesDependencyRegistrar.registerFacesDependencies(beanFactory); } }
/** * Register web-specific scopes ("request", "session", "globalSession") * with the given BeanFactory, as used by the Portlet ApplicationContext. * @param beanFactory the BeanFactory to configure * @param pc the PortletContext that we're running within */ static void registerPortletApplicationScopes(ConfigurableListableBeanFactory beanFactory, PortletContext pc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false)); beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true)); if (pc != null) { PortletContextScope appScope = new PortletContextScope(pc); beanFactory.registerScope(WebApplicationContext.SCOPE_APPLICATION, appScope); // Register as PortletContext attribute, for ContextCleanupListener to detect it. pc.setAttribute(PortletContextScope.class.getName(), appScope); } beanFactory.registerResolvableDependency(PortletRequest.class, new RequestObjectFactory()); beanFactory.registerResolvableDependency(PortletSession.class, new SessionObjectFactory()); beanFactory.registerResolvableDependency(WebRequest.class, new WebRequestObjectFactory()); }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); } }
public static MergeClassPathXMLApplicationContext getContext() { try { if (mergeContext == null) { // Note that as of 2.2.0, this array will no longer include "bl-applicationContext-test", as we want that to // be the very last context loaded. String[] contexts = StandardConfigLocations.retrieveAll(StandardConfigLocations.TESTCONTEXTTYPE); // After the framework applicationContexts are loaded, we want the module ones List<String> additionalContexts = new ArrayList<String>(moduleContexts); // Lastly, we want the test applicationContext additionalContexts.add("bl-applicationContext-test.xml"); // If we're running in legacy test mode, we need that one too if (ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-Dlegacy=true")) { additionalContexts.add("bl-applicationContext-test-legacy.xml"); } String[] strArray = new String[additionalContexts.size()]; mergeContext = new MergeClassPathXMLApplicationContext(contexts, additionalContexts.toArray(strArray)); //allow for request-scoped beans that can occur in web application contexts RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest())); mergeContext.getBeanFactory().registerScope("request", new RequestScope()); } } catch (Exception e) { throw new RuntimeException(e); } return mergeContext; }
public static MergeClassPathXMLApplicationContext getContext() { try { if (mergeContext == null) { // Note that as of 2.2.0, this array will no longer include "spark-applicationContext-test", as we want that to // be the very last context loaded. String[] contexts = StandardConfigLocations.retrieveAll(StandardConfigLocations.TESTCONTEXTTYPE); // After the framework applicationContexts are loaded, we want the module ones List<String> additionalContexts = new ArrayList<String>(moduleContexts); // Lastly, we want the test applicationContext additionalContexts.add("spark-applicationContext-test.xml"); // If we're running in legacy test mode, we need that one too if (ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-Dlegacy=true")) { additionalContexts.add("spark-applicationContext-test-legacy.xml"); } String[] strArray = new String[additionalContexts.size()]; mergeContext = new MergeClassPathXMLApplicationContext(contexts, additionalContexts.toArray(strArray)); //allow for request-scoped beans that can occur in web application contexts RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest())); mergeContext.getBeanFactory().registerScope("request", new RequestScope()); } } catch (Exception e) { throw new RuntimeException(e); } return mergeContext; }
public static MergeClassPathXMLApplicationContext getContext() { try { if (mergeContext == null) { // Note that as of 2.2.0, this array will no longer include "bl-applicationContext-test", as we want that to // be the very last context loaded. String[] contexts = StandardConfigLocations.retrieveAll(StandardConfigLocations.TESTCONTEXTTYPE); // After the framework applicationContexts are loaded, we want the module ones List<String> additionalContexts = new ArrayList<String>(moduleContexts); // We need the content applicationContexts and admin applicationContexts additionalContexts.add("bl-open-admin-contentClient-applicationContext.xml"); additionalContexts.add("bl-open-admin-contentCreator-applicationContext.xml"); additionalContexts.add("bl-admin-applicationContext.xml"); // Lastly, we want the test applicationContext additionalContexts.add("bl-applicationContext-test.xml"); // If we're running in legacy test mode, we need that one too if (ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-Dlegacy=true")) { additionalContexts.add("bl-applicationContext-test-legacy.xml"); } String[] strArray = new String[additionalContexts.size()]; mergeContext = new MergeClassPathXMLApplicationContext(contexts, additionalContexts.toArray(strArray)); //allow for request-scoped beans that can occur in web application contexts RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest())); mergeContext.getBeanFactory().registerScope("request", new RequestScope()); } } catch (Exception e) { throw new RuntimeException(e); } return mergeContext; }
public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext( this.beanFactory, new RequestScope()); } }
private void addCustomScopeConfigurerBean() { AutowireCapableBeanFactory autowireCapableBeanFactory = getAutowireCapableBeanFactory(); CustomScopeConfigurer customScopeConfigurer = (CustomScopeConfigurer) autowireCapableBeanFactory.createBean(CustomScopeConfigurer.class); HashMap map = new HashMap(); map.put(RequestManager.SESSION, SessionScope.class); map.put(RequestManager.REQUEST, RequestScope.class); customScopeConfigurer.setScopes(map); autowireCapableBeanFactory.initializeBean(customScopeConfigurer, SCOPE_CONFIGURER); }
public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); } }
/** * @param beanFactory a bean factory to use for resolving ${...} placeholder * and #{...} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); }
/** * @param beanFactory a bean factory to use for resolving ${...} placeholder * and #{...} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ public AbstractNamedValueMethodArgumentResolver(ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null) ? new BeanExpressionContext(beanFactory, new RequestScope()) : null; }