Java Code Examples for org.springframework.aop.scope.ScopedProxyUtils#createScopedProxy()

The following examples show how to use org.springframework.aop.scope.ScopedProxyUtils#createScopedProxy() . 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: ScopedProxyBeanDefinitionDecorator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example 2
Source File: ScopedProxyBeanDefinitionDecorator.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example 3
Source File: ScopedProxyBeanDefinitionDecorator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example 4
Source File: ScopedProxyBeanDefinitionDecorator.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example 5
Source File: RefreshAutoConfiguration.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
		throws BeansException {
	bindEnvironmentIfNeeded(registry);
	for (String name : registry.getBeanDefinitionNames()) {
		BeanDefinition definition = registry.getBeanDefinition(name);
		if (isApplicable(registry, name, definition)) {
			BeanDefinitionHolder holder = new BeanDefinitionHolder(definition,
					name);
			BeanDefinitionHolder proxy = ScopedProxyUtils
					.createScopedProxy(holder, registry, true);
			definition.setScope("refresh");
			if (registry.containsBeanDefinition(proxy.getBeanName())) {
				registry.removeBeanDefinition(proxy.getBeanName());
			}
			registry.registerBeanDefinition(proxy.getBeanName(),
					proxy.getBeanDefinition());
		}
	}
}
 
Example 6
Source File: ConfigurationClassPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void postProcessorDoesNotOverrideRegularBeanDefinitionsEvenWithScopedProxy() {
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setResource(new DescriptiveResource("XML or something"));
	BeanDefinitionHolder proxied = ScopedProxyUtils.createScopedProxy(
			new BeanDefinitionHolder(rbd, "bar"), beanFactory, true);
	beanFactory.registerBeanDefinition("bar", proxied.getBeanDefinition());
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.getBean("foo", Foo.class);
	beanFactory.getBean("bar", TestBean.class);
}
 
Example 7
Source File: ConfigurationClassPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void postProcessorDoesNotOverrideRegularBeanDefinitionsEvenWithScopedProxy() {
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setResource(new DescriptiveResource("XML or something"));
	BeanDefinitionHolder proxied = ScopedProxyUtils.createScopedProxy(
			new BeanDefinitionHolder(rbd, "bar"), beanFactory, true);
	beanFactory.registerBeanDefinition("bar", proxied.getBeanDefinition());
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.getBean("foo", Foo.class);
	beanFactory.getBean("bar", TestBean.class);
}
 
Example 8
Source File: ConfigurationClassPostProcessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void postProcessorDoesNotOverrideRegularBeanDefinitionsEvenWithScopedProxy() {
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setResource(new DescriptiveResource("XML or something"));
	BeanDefinitionHolder proxied = ScopedProxyUtils.createScopedProxy(
			new BeanDefinitionHolder(rbd, "bar"), beanFactory, true);
	beanFactory.registerBeanDefinition("bar", proxied.getBeanDefinition());
	beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
	ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
	pp.postProcessBeanFactory(beanFactory);
	beanFactory.getBean("foo", Foo.class);
	beanFactory.getBean("bar", TestBean.class);
}
 
Example 9
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public BeanDefinitionHolder proxyDataSource() {
	GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
	proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
	BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(
			proxyBeanDefinition, "dataSource2");
	ScopedProxyUtils.createScopedProxy(myDataSource,
			(BeanDefinitionRegistry) this.context.getBeanFactory(), true);
	return myDataSource;
}
 
Example 10
Source File: ScopedProxyCreator.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public static BeanDefinitionHolder createScopedProxy(
		BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry, boolean proxyTargetClass) {

	return ScopedProxyUtils.createScopedProxy(definitionHolder, registry, proxyTargetClass);
}
 
Example 11
Source File: ScopedProxyCreator.java    From java-technology-stack with MIT License 4 votes vote down vote up
public static BeanDefinitionHolder createScopedProxy(
		BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry, boolean proxyTargetClass) {

	return ScopedProxyUtils.createScopedProxy(definitionHolder, registry, proxyTargetClass);
}
 
Example 12
Source File: ScopedProxyCreator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static BeanDefinitionHolder createScopedProxy(
		BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry, boolean proxyTargetClass) {

	return ScopedProxyUtils.createScopedProxy(definitionHolder, registry, proxyTargetClass);
}
 
Example 13
Source File: ScopedProxyCreator.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public static BeanDefinitionHolder createScopedProxy(
		BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry, boolean proxyTargetClass) {

	return ScopedProxyUtils.createScopedProxy(definitionHolder, registry, proxyTargetClass);
}
 
Example 14
Source File: Scopifier.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public static BeanDefinitionHolder createScopedProxy(String beanName, BeanDefinition definition, BeanDefinitionRegistry registry, boolean proxyTargetClass) {
	BeanDefinitionHolder proxyHolder = ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(definition, beanName), registry, proxyTargetClass);
	registry.registerBeanDefinition(beanName, proxyHolder.getBeanDefinition());
	return proxyHolder;
}