org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource Java Examples

The following examples show how to use org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource. 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: QuickTargetSourceCreator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {

	if (beanName.startsWith(PREFIX_COMMONS_POOL)) {
		CommonsPool2TargetSource cpts = new CommonsPool2TargetSource();
		cpts.setMaxSize(25);
		return cpts;
	}
	else if (beanName.startsWith(PREFIX_THREAD_LOCAL)) {
		return new ThreadLocalTargetSource();
	}
	else if (beanName.startsWith(PREFIX_PROTOTYPE)) {
		return new PrototypeTargetSource();
	}
	else {
		// No match. Don't create a custom target source.
		return null;
	}
}
 
Example #2
Source File: QuickTargetSourceCreator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {

	if (beanName.startsWith(PREFIX_COMMONS_POOL)) {
		CommonsPool2TargetSource cpts = new CommonsPool2TargetSource();
		cpts.setMaxSize(25);
		return cpts;
	}
	else if (beanName.startsWith(PREFIX_THREAD_LOCAL)) {
		return new ThreadLocalTargetSource();
	}
	else if (beanName.startsWith(PREFIX_PROTOTYPE)) {
		return new PrototypeTargetSource();
	}
	else {
		// No match. Don't create a custom target source.
		return null;
	}
}
 
Example #3
Source File: AbstractBeanFactoryBasedTargetSourceCreator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
	AbstractBeanFactoryBasedTargetSource targetSource =
			createBeanFactoryBasedTargetSource(beanClass, beanName);
	if (targetSource == null) {
		return null;
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
	}

	DefaultListableBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);

	// We need to override just this bean definition, as it may reference other beans
	// and we're happy to take the parent's definition for those.
	// Always use prototype scope if demanded.
	BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
	GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
	if (isPrototypeBased()) {
		bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	}
	internalBeanFactory.registerBeanDefinition(beanName, bdCopy);

	// Complete configuring the PrototypeTargetSource.
	targetSource.setTargetBeanName(beanName);
	targetSource.setBeanFactory(internalBeanFactory);

	return targetSource;
}
 
Example #4
Source File: LazyInitTargetSourceCreator.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {

	if (getBeanFactory() instanceof ConfigurableListableBeanFactory) {
		BeanDefinition definition =
				((ConfigurableListableBeanFactory) getBeanFactory()).getBeanDefinition(beanName);
		if (definition.isLazyInit()) {
			return new LazyInitTargetSource();
		}
	}
	return null;
}
 
Example #5
Source File: AutoProxyLazyInitTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) {
	if ("myBean".equals(beanName)) {
		assertEquals(MyBean.class, beanClass);
	}
	return super.createBeanFactoryBasedTargetSource(beanClass, beanName);
}
 
Example #6
Source File: AdvisorAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {
	if (!beanName.startsWith("prototype")) {
		return null;
	}
	return new PrototypeTargetSource();
}
 
Example #7
Source File: AutoProxyLazyInitTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) {
	if ("myBean".equals(beanName)) {
		assertEquals(MyBean.class, beanClass);
	}
	return super.createBeanFactoryBasedTargetSource(beanClass, beanName);
}
 
Example #8
Source File: AdvisorAutoProxyCreatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {
	if (!beanName.startsWith("prototype")) {
		return null;
	}
	return new PrototypeTargetSource();
}
 
Example #9
Source File: AbstractBeanFactoryBasedTargetSourceCreator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
	AbstractBeanFactoryBasedTargetSource targetSource =
			createBeanFactoryBasedTargetSource(beanClass, beanName);
	if (targetSource == null) {
		return null;
	}

	if (logger.isDebugEnabled()) {
		logger.debug("Configuring AbstractBeanFactoryBasedTargetSource: " + targetSource);
	}

	DefaultListableBeanFactory internalBeanFactory = getInternalBeanFactoryForBean(beanName);

	// We need to override just this bean definition, as it may reference other beans
	// and we're happy to take the parent's definition for those.
	// Always use prototype scope if demanded.
	BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);
	GenericBeanDefinition bdCopy = new GenericBeanDefinition(bd);
	if (isPrototypeBased()) {
		bdCopy.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	}
	internalBeanFactory.registerBeanDefinition(beanName, bdCopy);

	// Complete configuring the PrototypeTargetSource.
	targetSource.setTargetBeanName(beanName);
	targetSource.setBeanFactory(internalBeanFactory);

	return targetSource;
}
 
Example #10
Source File: LazyInitTargetSourceCreator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {

	if (getBeanFactory() instanceof ConfigurableListableBeanFactory) {
		BeanDefinition definition =
				((ConfigurableListableBeanFactory) getBeanFactory()).getBeanDefinition(beanName);
		if (definition.isLazyInit()) {
			return new LazyInitTargetSource();
		}
	}
	return null;
}
 
Example #11
Source File: AutoProxyLazyInitTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) {
	if ("myBean".equals(beanName)) {
		assertEquals(MyBean.class, beanClass);
	}
	return super.createBeanFactoryBasedTargetSource(beanClass, beanName);
}
 
Example #12
Source File: AdvisorAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName) {
	if (!beanName.startsWith("prototype")) {
		return null;
	}
	return new PrototypeTargetSource();
}
 
Example #13
Source File: AbstractBeanFactoryBasedTargetSourceCreator.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource
 * if they wish to create a custom TargetSource for this bean, or {@code null} if they are
 * not interested it in, in which case no special target source will be created.
 * Subclasses should not call {@code setTargetBeanName} or {@code setBeanFactory}
 * on the AbstractPrototypeBasedTargetSource: This class' implementation of
 * {@code getTargetSource()} will do that.
 * @param beanClass the class of the bean to create a TargetSource for
 * @param beanName the name of the bean
 * @return the AbstractPrototypeBasedTargetSource, or {@code null} if we don't match this
 */
@Nullable
protected abstract AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName);
 
Example #14
Source File: AbstractBeanFactoryBasedTargetSourceCreator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Subclasses must implement this method to return a new AbstractPrototypeBasedTargetSource
 * if they wish to create a custom TargetSource for this bean, or {@code null} if they are
 * not interested it in, in which case no special target source will be created.
 * Subclasses should not call {@code setTargetBeanName} or {@code setBeanFactory}
 * on the AbstractPrototypeBasedTargetSource: This class' implementation of
 * {@code getTargetSource()} will do that.
 * @param beanClass the class of the bean to create a TargetSource for
 * @param beanName the name of the bean
 * @return the AbstractPrototypeBasedTargetSource, or {@code null} if we don't match this
 */
protected abstract AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
		Class<?> beanClass, String beanName);