Java Code Examples for org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerScope()

The following examples show how to use org.springframework.beans.factory.config.ConfigurableListableBeanFactory#registerScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebApplicationContextUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 2
Source File: WebApplicationContextUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 3
Source File: WebApplicationContextUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 4
Source File: PortletApplicationContextUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source File: WebApplicationContextUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: WebContextTestExecutionListener.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareTestInstance(TestContext testContext) throws Exception {

    if (testContext.getApplicationContext() instanceof GenericApplicationContext) {
        GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext();
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Scope requestScope = new SimpleThreadScope();
        beanFactory.registerScope("request", requestScope);
        Scope sessionScope = new SimpleThreadScope();
        beanFactory.registerScope("session", sessionScope);
    }
}
 
Example 7
Source File: ProcessScope.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

		beanFactory.registerScope(ProcessScope.PROCESS_SCOPE_NAME, this);

		Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, "BeanFactory was not a BeanDefinitionRegistry, so ProcessScope cannot be used.");

		BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

		for (String beanName : beanFactory.getBeanDefinitionNames()) {
			BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
			// Replace this or any of its inner beans with scoped proxy if it has this scope
			boolean scoped = PROCESS_SCOPE_NAME.equals(definition.getScope());
			Scopifier scopifier = new Scopifier(registry, PROCESS_SCOPE_NAME, proxyTargetClass, scoped);
			scopifier.visitBeanDefinition(definition);
			if (scoped) {
				Scopifier.createScopedProxy(beanName, definition, registry, proxyTargetClass);
			}
		}

		beanFactory.registerSingleton(ProcessScope.PROCESS_SCOPE_PROCESS_VARIABLES_SINGLETON, this.processVariablesMap);
		beanFactory.registerResolvableDependency(ProcessInstance.class,  createSharedProcessInstance());
	}
 
Example 8
Source File: ScopePostProcessor.java    From mcspring-boot with MIT License 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
    factory.registerScope("sender", senderContextScope);
    Arrays.stream(factory.getBeanDefinitionNames()).forEach(beanName -> {
        val beanDef = factory.getBeanDefinition(beanName);
        val beanType = factory.getType(beanName);
        if (beanType != null && beanType.isAssignableFrom(Listener.class)) {
            beanDef.setScope(SCOPE_SINGLETON);
        }
    });
}
 
Example 9
Source File: GenericScope.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
		throws BeansException {
	this.beanFactory = beanFactory;
	beanFactory.registerScope(this.name, this);
	setSerializationId(beanFactory);
}
 
Example 10
Source File: CustomScopeRegistryBeanFactoryPostProcessor.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	beanFactory.registerScope("periodical", new PeriodicalScopeConfigurer());
}
 
Example 11
Source File: GrpcRequestScope.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
    factory.registerScope(GRPC_REQUEST_SCOPE_NAME, this);
}
 
Example 12
Source File: LoadingSessionScope.java    From rdf2neo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void postProcessBeanFactory ( ConfigurableListableBeanFactory beanFactory ) throws BeansException
{
	beanFactory.registerScope ( "loadingSession", beanFactory.getBean ( LoadingSessionScope.class ) );
}
 
Example 13
Source File: GrpcRequestScope.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
    factory.registerScope(GRPC_REQUEST_SCOPE_NAME, this);
}
 
Example 14
Source File: JobScopeIteration.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    beanFactory.registerScope(SCOPE_NAME, this);
}
 
Example 15
Source File: TenantBeanFactoryPostProcessor.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
    factory.registerScope("tenant", new TenantScope());
}