/** * Create a new {@link AbstractNamedValueMethodArgumentResolver} instance. * @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(@Nullable ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); }
/** * Create a new {@link AbstractNamedValueMethodArgumentResolver} instance. * @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(@Nullable ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); }
@Before public void setup() { this.beanFactory.registerScope("request", new RequestScope()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.loadBeanDefinitions(new ClassPathResource("requestScopedProxyTests.xml", getClass())); this.beanFactory.preInstantiateSingletons(); }
/** * 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, @Nullable ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope()); 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); } }
@Before public void setup() throws Exception { this.beanFactory.registerScope("request", new RequestScope()); this.beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver()); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.loadBeanDefinitions(new ClassPathResource("requestScopeTests.xml", getClass())); this.beanFactory.preInstantiateSingletons(); }
/** * 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, @Nullable ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope()); 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); } }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); } }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); } }
public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ConfigurableBeanFactory) { this.beanFactory = (ConfigurableBeanFactory) beanFactory; this.expressionContext = new BeanExpressionContext(this.beanFactory, new RequestScope()); } }
/** * Create a new {@link AbstractNamedValueMethodArgumentResolver} instance. * @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(@Nullable 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(@Nullable ConfigurableBeanFactory beanFactory) { this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, new RequestScope()) : null); }
public void registerRequestScope(ConfigurableBeanFactory beanFactory) { beanFactory.registerScope(SCOPE_REQUEST, new RequestScope()); } }
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); // Ensure the current ClassLoader is used, or otherwise setting the ResourceLoader would suppress it ClassLoader classLoaderToUse = flowContext.getClassLoader(); flowContext.setClassLoader(classLoaderToUse); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }
/** * 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, @Nullable ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope()); 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", "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, @Nullable ServletContext sc) { beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope()); beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope()); 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()); }
/** * 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()); }
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); if (JdkVersion.isAtLeastJava15()) { AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); } new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }
private GenericApplicationContext createFlowApplicationContext(Resource[] resources) { ApplicationContext parent = getContext().getApplicationContext(); GenericApplicationContext flowContext; if (parent instanceof WebApplicationContext) { GenericWebApplicationContext webContext = new GenericWebApplicationContext(); webContext.setServletContext(((WebApplicationContext) parent).getServletContext()); flowContext = webContext; } else { flowContext = new GenericApplicationContext(); } flowContext.setDisplayName("Flow ApplicationContext [" + getContext().getFlowId() + "]"); flowContext.setParent(parent); flowContext.getBeanFactory().registerScope("request", new RequestScope()); flowContext.getBeanFactory().registerScope("flash", new FlashScope()); flowContext.getBeanFactory().registerScope("view", new ViewScope()); flowContext.getBeanFactory().registerScope("flow", new FlowScope()); flowContext.getBeanFactory().registerScope("conversation", new ConversationScope()); // Ensure the current ClassLoader is used, or otherwise setting the ResourceLoader would suppress it ClassLoader classLoaderToUse = flowContext.getClassLoader(); flowContext.setClassLoader(classLoaderToUse); Resource flowResource = flowModelHolder.getFlowModelResource(); flowContext.setResourceLoader(new FlowRelativeResourceLoader(flowResource)); AnnotationConfigUtils.registerAnnotationConfigProcessors(flowContext); new XmlBeanDefinitionReader(flowContext).loadBeanDefinitions(resources); registerFlowBeans(flowContext.getBeanFactory()); registerMessageSource(flowContext, flowResource); flowContext.refresh(); return flowContext; }