use of org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor in project HotswapAgent by HotswapProjects.
the class ResetBeanPostProcessorCaches method reset.
/**
* Reset all post processors associated with a bean factory.
*
* @param beanFactory beanFactory to use
*/
public static void reset(DefaultListableBeanFactory beanFactory) {
Class<?> c = getReflectionUtilsClassOrNull();
if (c != null) {
try {
Method m = c.getDeclaredMethod("clearCache");
m.invoke(c);
} catch (Exception version42Failed) {
try {
// spring 4.0.x, 4.1.x without clearCache method, clear manually
Field declaredMethodsCache = c.getDeclaredField("declaredMethodsCache");
declaredMethodsCache.setAccessible(true);
((Map) declaredMethodsCache.get(null)).clear();
Field declaredFieldsCache = c.getDeclaredField("declaredFieldsCache");
declaredFieldsCache.setAccessible(true);
((Map) declaredFieldsCache.get(null)).clear();
} catch (Exception version40Failed) {
LOGGER.debug("Failed to clear internal method/field cache, it's normal with spring 4.1x or lower", version40Failed);
}
}
LOGGER.trace("Cleared Spring 4.2+ internal method/field cache.");
}
for (BeanPostProcessor bpp : beanFactory.getBeanPostProcessors()) {
if (bpp instanceof AutowiredAnnotationBeanPostProcessor) {
resetAutowiredAnnotationBeanPostProcessorCache((AutowiredAnnotationBeanPostProcessor) bpp);
} else if (bpp instanceof InitDestroyAnnotationBeanPostProcessor) {
resetInitDestroyAnnotationBeanPostProcessorCache((InitDestroyAnnotationBeanPostProcessor) bpp);
}
}
}
use of org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class CommonAnnotationBeanPostProcessorTests method testPostConstructAndPreDestroyWithManualConfiguration.
@Test
public void testPostConstructAndPreDestroyWithManualConfiguration() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
bpp.setInitAnnotationType(PostConstruct.class);
bpp.setDestroyAnnotationType(PreDestroy.class);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
assertThat(bean.initCalled).isTrue();
bf.destroySingletons();
assertThat(bean.destroyCalled).isTrue();
}
use of org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor in project spring-framework by spring-projects.
the class CommonAnnotationBeanPostProcessorTests method testSerializationWithManualConfiguration.
@Test
public void testSerializationWithManualConfiguration() throws Exception {
InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
bpp.setInitAnnotationType(PostConstruct.class);
bpp.setDestroyAnnotationType(PreDestroy.class);
InitDestroyAnnotationBeanPostProcessor bpp2 = SerializationTestUtils.serializeAndDeserialize(bpp);
AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean();
bpp2.postProcessBeforeDestruction(bean, "annotatedBean");
assertThat(bean.destroyCalled).isTrue();
}
Aggregations