当前位置: 首页>>代码示例>>Java>>正文


Java Scope类代码示例

本文整理汇总了Java中org.springframework.beans.factory.config.Scope的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Scope类属于org.springframework.beans.factory.config包,在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: destroyScopedBean

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Override
public void destroyScopedBean(String beanName) {
	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
	if (mbd.isSingleton() || mbd.isPrototype()) {
		throw new IllegalArgumentException(
				"Bean name '" + beanName + "' does not correspond to an object in a mutable scope");
	}
	String scopeName = mbd.getScope();
	Scope scope = this.scopes.get(scopeName);
	if (scope == null) {
		throw new IllegalStateException("No Scope SPI registered for scope '" + scopeName + "'");
	}
	Object bean = scope.remove(beanName);
	if (bean != null) {
		destroyBean(beanName, bean, mbd);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:AbstractBeanFactory.java

示例2: registerDisposableBeanIfNecessary

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
/**
 * Add the given bean to the list of disposable beans in this factory,
 * registering its DisposableBean interface and/or the given destroy method
 * to be called on factory shutdown (if applicable). Only applies to singletons.
 * @param beanName the name of the bean
 * @param bean the bean instance
 * @param mbd the bean definition for the bean
 * @see RootBeanDefinition#isSingleton
 * @see RootBeanDefinition#getDependsOn
 * @see #registerDisposableBean
 * @see #registerDependentBean
 */
protected void registerDisposableBeanIfNecessary(String beanName, Object bean, RootBeanDefinition mbd) {
	AccessControlContext acc = (System.getSecurityManager() != null ? getAccessControlContext() : null);
	if (!mbd.isPrototype() && requiresDestruction(bean, mbd)) {
		if (mbd.isSingleton()) {
			// Register a DisposableBean implementation that performs all destruction
			// work for the given bean: DestructionAwareBeanPostProcessors,
			// DisposableBean interface, custom destroy method.
			registerDisposableBean(beanName,
					new DisposableBeanAdapter(bean, beanName, mbd, getBeanPostProcessors(), acc));
		}
		else {
			// A bean with a custom scope...
			Scope scope = this.scopes.get(mbd.getScope());
			if (scope == null) {
				throw new IllegalStateException("No Scope registered for scope '" + mbd.getScope() + "'");
			}
			scope.registerDestructionCallback(beanName,
					new DisposableBeanAdapter(bean, beanName, mbd, getBeanPostProcessors(), acc));
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:AbstractBeanFactory.java

示例3: registerScope

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Override
public void registerScope(String scopeName, Scope scope) {
	Assert.notNull(scopeName, "Scope identifier must not be null");
	Assert.notNull(scope, "Scope must not be null");
	if (SCOPE_SINGLETON.equals(scopeName) || SCOPE_PROTOTYPE.equals(scopeName)) {
		throw new IllegalArgumentException("Cannot replace existing scopes 'singleton' and 'prototype'");
	}
	Scope previous = this.scopes.put(scopeName, scope);
	if (previous != null && previous != scope) {
		if (logger.isInfoEnabled()) {
			logger.info("Replacing scope '" + scopeName + "' from [" + previous + "] to [" + scope + "]");
		}
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Registering scope '" + scopeName + "' with implementation [" + scope + "]");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractBeanFactory.java

示例4: destroyScopedBean

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Override
public void destroyScopedBean(String beanName) {
	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
	if (mbd.isSingleton() || mbd.isPrototype()) {
		throw new IllegalArgumentException(
				"Bean name '" + beanName + "' does not correspond to an object in a mutable scope");
	}
	String scopeName = mbd.getScope();
	Scope scope = this.scopes.get(scopeName);
	if (scope == null) {
		throw new IllegalStateException("No Scope SPI registered for scope name '" + scopeName + "'");
	}
	Object bean = scope.remove(beanName);
	if (bean != null) {
		destroyBean(beanName, bean, mbd);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AbstractBeanFactory.java

示例5: registerDisposableBeanIfNecessary

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
/**
 * Add the given bean to the list of disposable beans in this factory,
 * registering its DisposableBean interface and/or the given destroy method
 * to be called on factory shutdown (if applicable). Only applies to singletons.
 * @param beanName the name of the bean
 * @param bean the bean instance
 * @param mbd the bean definition for the bean
 * @see RootBeanDefinition#isSingleton
 * @see RootBeanDefinition#getDependsOn
 * @see #registerDisposableBean
 * @see #registerDependentBean
 */
protected void registerDisposableBeanIfNecessary(String beanName, Object bean, RootBeanDefinition mbd) {
	AccessControlContext acc = (System.getSecurityManager() != null ? getAccessControlContext() : null);
	if (!mbd.isPrototype() && requiresDestruction(bean, mbd)) {
		if (mbd.isSingleton()) {
			// Register a DisposableBean implementation that performs all destruction
			// work for the given bean: DestructionAwareBeanPostProcessors,
			// DisposableBean interface, custom destroy method.
			registerDisposableBean(beanName,
					new DisposableBeanAdapter(bean, beanName, mbd, getBeanPostProcessors(), acc));
		}
		else {
			// A bean with a custom scope...
			Scope scope = this.scopes.get(mbd.getScope());
			if (scope == null) {
				throw new IllegalStateException("No Scope registered for scope name '" + mbd.getScope() + "'");
			}
			scope.registerDestructionCallback(beanName,
					new DisposableBeanAdapter(bean, beanName, mbd, getBeanPostProcessors(), acc));
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:AbstractBeanFactory.java

示例6: doesNotReplaceExistingScopes

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Test
public void doesNotReplaceExistingScopes() throws Exception { // gh-2082
	Scope scope = mock(Scope.class);
	ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
	factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope);
	factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope);
	factory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, scope);
	addEmbeddedServletContainerFactoryBean();
	this.context.refresh();
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST))
			.isSameAs(scope);
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_SESSION))
			.isSameAs(scope);
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_GLOBAL_SESSION))
			.isSameAs(scope);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:EmbeddedWebApplicationContextTests.java

示例7: _get

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object _get(Map map, String name, ObjectFactory factory, boolean registerCb) {
	Object o = map.get(name);
	if(o == null) {
		o = factory.getObject();
		map.put(name, o);
		
		if(registerCb && defaultDestructionCallback != null) {
			try {
				Constructor c = defaultDestructionCallback.getConstructor(Scope.class,String.class);
				registerDestructionCallback(name, (Runnable) c.newInstance(this,name));
			} catch(Exception e) {
				log.error("Could not setup destruction callback: " + name, e);
			}
		}
	}
	return o;
}
 
开发者ID:jyore,项目名称:spring-scopes,代码行数:19,代码来源:AbstractScope.java

示例8: doesNotReplaceExistingScopes

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Test
public void doesNotReplaceExistingScopes() throws Exception { // gh-2082
	Scope scope = mock(Scope.class);
	ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
	factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope);
	factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope);
	factory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, scope);
	addEmbeddedServletContainerFactoryBean();
	this.context.refresh();
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST),
			sameInstance(scope));
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_SESSION),
			sameInstance(scope));
	assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_GLOBAL_SESSION),
			sameInstance(scope));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:EmbeddedWebApplicationContextTests.java

示例9: destroyScopedBean

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
public void destroyScopedBean(String beanName) {
	RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
	if (mbd.isSingleton() || mbd.isPrototype()) {
		throw new IllegalArgumentException(
				"Bean name '" + beanName + "' does not correspond to an object in a mutable scope");
	}
	String scopeName = mbd.getScope();
	Scope scope = this.scopes.get(scopeName);
	if (scope == null) {
		throw new IllegalStateException("No Scope SPI registered for scope '" + scopeName + "'");
	}
	Object bean = scope.remove(beanName);
	if (bean != null) {
		destroyBean(beanName, bean, mbd);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:AbstractBeanFactory.java

示例10: cleanOsgiBundleScope

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
private void cleanOsgiBundleScope(ConfigurableListableBeanFactory beanFactory) {
	Scope scope = beanFactory.getRegisteredScope(OsgiBundleScope.SCOPE_NAME);
	if (scope != null && scope instanceof OsgiBundleScope) {
		if (logger.isDebugEnabled())
			logger.debug("Destroying existing bundle scope beans...");
		((OsgiBundleScope) scope).destroy();
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:9,代码来源:AbstractOsgiBundleApplicationContext.java

示例11: registerScope

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@Override
public void registerScope(String scopeName, Scope scope) {
	Assert.notNull(scopeName, "Scope identifier must not be null");
	Assert.notNull(scope, "Scope must not be null");
	if (SCOPE_SINGLETON.equals(scopeName) || SCOPE_PROTOTYPE.equals(scopeName)) {
		throw new IllegalArgumentException("Cannot replace existing scopes 'singleton' and 'prototype'");
	}
	this.scopes.put(scopeName, scope);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:AbstractBeanFactory.java

示例12: ExistingWebApplicationScopes

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
public ExistingWebApplicationScopes(ConfigurableListableBeanFactory beanFactory) {
	this.beanFactory = beanFactory;
	for (String scopeName : SCOPES) {
		Scope scope = beanFactory.getRegisteredScope(scopeName);
		if (scope != null) {
			this.scopes.put(scopeName, scope);
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:EmbeddedWebApplicationContext.java

示例13: restore

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
public void restore() {
	for (Map.Entry<String, Scope> entry : this.scopes.entrySet()) {
		if (logger.isInfoEnabled()) {
			logger.info("Restoring user defined scope " + entry.getKey());
		}
		this.beanFactory.registerScope(entry.getKey(), entry.getValue());
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:EmbeddedWebApplicationContext.java

示例14: prepareTestInstance

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:DHBW-Karlsruhe,项目名称:businesshorizon2,代码行数:13,代码来源:TestExecutionListener.java

示例15: prepareTestInstance

import org.springframework.beans.factory.config.Scope; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:primetoninc,项目名称:euler-chidi,代码行数:13,代码来源:WebContextTestExecutionListener.java


注:本文中的org.springframework.beans.factory.config.Scope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。