org.springframework.core.OverridingClassLoader Java Examples

The following examples show how to use org.springframework.core.OverridingClassLoader. 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: BeanFactoryGenericsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test  // SPR-16720
public void parameterizedInstanceFactoryMethodWithTempClassLoader() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setTempClassLoader(new OverridingClassLoader(getClass().getClassLoader()));

	RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
	bf.registerBeanDefinition("mocksControl", rbd);

	rbd = new RootBeanDefinition();
	rbd.setFactoryBeanName("mocksControl");
	rbd.setFactoryMethodName("createMock");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
	bf.registerBeanDefinition("mock", rbd);

	assertTrue(bf.isTypeMatch("mock", Runnable.class));
	assertTrue(bf.isTypeMatch("mock", Runnable.class));
	assertEquals(Runnable.class, bf.getType("mock"));
	assertEquals(Runnable.class, bf.getType("mock"));
	Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
	assertEquals(1, beans.size());
}
 
Example #2
Source File: CachedIntrospectionResultsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void acceptAndClearClassLoader() throws Exception {
	BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));

	ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
	Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.acceptClassLoader(child);
	bw = new BeanWrapperImpl(tbClass);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.clearClassLoader(child);
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));

	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
}
 
Example #3
Source File: BeanFactoryGenericsTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test  // SPR-16720
public void parameterizedInstanceFactoryMethodWithTempClassLoader() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setTempClassLoader(new OverridingClassLoader(getClass().getClassLoader()));

	RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
	bf.registerBeanDefinition("mocksControl", rbd);

	rbd = new RootBeanDefinition();
	rbd.setFactoryBeanName("mocksControl");
	rbd.setFactoryMethodName("createMock");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
	bf.registerBeanDefinition("mock", rbd);

	assertTrue(bf.isTypeMatch("mock", Runnable.class));
	assertTrue(bf.isTypeMatch("mock", Runnable.class));
	assertEquals(Runnable.class, bf.getType("mock"));
	assertEquals(Runnable.class, bf.getType("mock"));
	Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
	assertEquals(1, beans.size());
}
 
Example #4
Source File: CachedIntrospectionResultsTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void acceptAndClearClassLoader() throws Exception {
	BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));

	ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
	Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.acceptClassLoader(child);
	bw = new BeanWrapperImpl(tbClass);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.clearClassLoader(child);
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));

	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
}
 
Example #5
Source File: CachedIntrospectionResultsTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void acceptAndClearClassLoader() throws Exception {
	BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));

	ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
	Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.acceptClassLoader(child);
	bw = new BeanWrapperImpl(tbClass);
	assertTrue(bw.isWritableProperty("name"));
	assertTrue(bw.isWritableProperty("age"));
	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
	CachedIntrospectionResults.clearClassLoader(child);
	assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));

	assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
}
 
Example #6
Source File: ReflectiveLoadTimeWeaver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	if (this.getThrowawayClassLoaderMethod != null) {
		ClassLoader target = (ClassLoader)
				ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader);
		return (target instanceof DecoratingClassLoader ? target :
				new OverridingClassLoader(this.classLoader, target));
	}
	else {
		return new SimpleThrowawayClassLoader(this.classLoader);
	}
}
 
Example #7
Source File: ReflectiveLoadTimeWeaver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	if (this.getThrowawayClassLoaderMethod != null) {
		ClassLoader target = (ClassLoader)
				ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader);
		return (target instanceof DecoratingClassLoader ? target :
				new OverridingClassLoader(this.classLoader, target));
	}
	else {
		return new SimpleThrowawayClassLoader(this.classLoader);
	}
}
 
Example #8
Source File: ReflectiveLoadTimeWeaver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	if (this.getThrowawayClassLoaderMethod != null) {
		ClassLoader target = (ClassLoader)
				ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader);
		return (target instanceof DecoratingClassLoader ? target :
				new OverridingClassLoader(this.classLoader, target));
	}
	else {
		return new SimpleThrowawayClassLoader(this.classLoader);
	}
}
 
Example #9
Source File: WebLogicLoadTimeWeaver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}
 
Example #10
Source File: WebSphereLoadTimeWeaver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}
 
Example #11
Source File: WebLogicLoadTimeWeaver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}
 
Example #12
Source File: WebSphereLoadTimeWeaver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}
 
Example #13
Source File: WebLogicLoadTimeWeaver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}
 
Example #14
Source File: WebSphereLoadTimeWeaver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ClassLoader getThrowawayClassLoader() {
	return new OverridingClassLoader(this.classLoader.getClassLoader(),
			this.classLoader.getThrowawayClassLoader());
}