org.springframework.aop.target.PrototypeTargetSource Java Examples

The following examples show how to use org.springframework.aop.target.PrototypeTargetSource. 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: AdvisorAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #4
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 #5
Source File: AdvisorAutoProxyCreatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #6
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 #7
Source File: AdvisorAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #8
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();
}