@Override public void runBare() throws Throwable { testContextManager.prepareTestInstance(this); // this will initialize all dependencies try { super.runBare(); } finally { testContextManager.afterTestClass(); applicationContext.close(); clearTestContextCache(testContextManager); applicationContext = null; processEngine = null; testContextManager = null; CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader()); } }
private void initJavaBeansCache() { Class<?>[] classes = new Class<?>[] { OsgiServiceFactoryBean.class, OsgiServiceProxyFactoryBean.class, OsgiServiceCollectionProxyFactoryBean.class }; CachedIntrospectionResults.acceptClassLoader(OsgiStringUtils.class.getClassLoader()); for (Class<?> clazz : classes) { BeanUtils.getPropertyDescriptors(clazz); } }
private void configureIgnoreBeanInfo(ConfigurableEnvironment environment) { if (System.getProperty( CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME) == null) { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.beaninfo."); Boolean ignore = resolver.getProperty("ignore", Boolean.class, Boolean.TRUE); System.setProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME, ignore.toString()); } }
@After public void cleanup() { if (this.context != null) { this.context.close(); } System.clearProperty("the.property"); System.clearProperty("spring.config.location"); System.clearProperty("spring.main.banner-mode"); System.clearProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); }
@Test public void setIgnoreBeanInfoPropertyByDefault() throws Exception { this.initializer.setSearchNames("testproperties"); this.initializer.postProcessEnvironment(this.environment, this.application); String property = System .getProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); assertThat(property).isEqualTo("true"); }
@Test public void disableIgnoreBeanInfoProperty() throws Exception { this.initializer.setSearchNames("testproperties"); TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "spring.beaninfo.ignore=false"); this.initializer.postProcessEnvironment(this.environment, this.application); String property = System .getProperty(CachedIntrospectionResults.IGNORE_BEANINFO_PROPERTY_NAME); assertThat(property).isEqualTo("false"); }
private void cleanupKnownCaches() throws Exception { // Whilst not strictly necessary it helps to cleanup soft reference caches // early rather than waiting for memory limits to be reached clear(ResolvableType.class, "cache"); clear("org.springframework.core.SerializableTypeWrapper", "cache"); clear(CachedIntrospectionResults.class, "acceptedClassLoaders"); clear(CachedIntrospectionResults.class, "strongClassCache"); clear(CachedIntrospectionResults.class, "softClassCache"); clear(ReflectionUtils.class, "declaredFieldsCache"); clear(ReflectionUtils.class, "declaredMethodsCache"); clear(AnnotationUtils.class, "findAnnotationCache"); clear(AnnotationUtils.class, "annotatedInterfaceCache"); clear("com.sun.naming.internal.ResourceManager", "propertiesCache"); }
/** * Reset all caches. */ public static void reset() { resetTypeVariableCache(); resetAnnotationUtilsCache(); resetReflectionUtilsCache(); resetPropetyCache(); CachedIntrospectionResults.clearClassLoader(ResetSpringStaticCaches.class.getClassLoader()); }
private void destroyJavaBeansCache() { CachedIntrospectionResults.clearClassLoader(OsgiStringUtils.class.getClassLoader()); }
@Override public void contextInitialized(ServletContextEvent event) { CachedIntrospectionResults.acceptClassLoader(Thread.currentThread().getContextClassLoader()); }
@Override public void contextDestroyed(ServletContextEvent event) { CachedIntrospectionResults.clearClassLoader(Thread.currentThread().getContextClassLoader()); Introspector.flushCaches(); }
@Override public void stop() throws Exception { // must clear this Spring cache to avoid any memory leaks CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader()); super.stop(); }
public void contextInitialized(ServletContextEvent event) { CachedIntrospectionResults.acceptClassLoader(Thread.currentThread().getContextClassLoader()); }
public void contextDestroyed(ServletContextEvent event) { CachedIntrospectionResults.clearClassLoader(Thread.currentThread().getContextClassLoader()); Introspector.flushCaches(); }
@RequestMapping(method = RequestMethod.GET, value = "/registerBean") @ResponseBody private String registerBean( @RequestParam(value = "beanName", required = true) String beanName, @RequestParam(value = "beanType", required = true) String beanType) { try { /* String demoMessage = getDemoMessage(); */ Class<?> c; c = Class.forName(beanType); CachedIntrospectionResults.clearClassLoader(c.getClassLoader()); beanFactory.registerBean(c, beanName, "prototype", false, true); Object myBean = beanFactory.getBean(beanName); String ret = PAGE_HEADER + SPRING_VERSION + BEAN_INFO_MSG + CLASSLOADER_DELAY + BEAN_INFO_HEADER + String.format(BEAN_INFO_FORMAT, beanName, myBean .getClass().getName(), myBean.toString()) /* * + * DEMO_MESSAGE_HEADER * + * tagHTML( * "p", * demoMessage * ) */; if (LOGGER.isDebugEnabled()) { LOGGER.debug(beanType); } /* CachedIntrospectionResults cir; */ /* * * if (ClassUtils.isCacheSafe(beanClass, * CachedIntrospectionResults.class.getClassLoader()) || * isClassLoaderAccepted(beanClass.getClassLoader())) { */ // CachedIntrospectionResults.clearClassLoader(c.getClassLoader()); /* tripsDemo.getMessage(); */ return ret; } catch (Exception e) { return String .format("Unable to create bean of type %s with the following error:</br>%s!", beanType, e.getMessage()); } }
/** * Reset Spring's common core caches, in particular the {@link ReflectionUtils}, * {@link ResolvableType} and {@link CachedIntrospectionResults} caches. * @since 4.2 * @see ReflectionUtils#clearCache() * @see ResolvableType#clearCache() * @see CachedIntrospectionResults#clearClassLoader(ClassLoader) */ protected void resetCommonCaches() { ReflectionUtils.clearCache(); ResolvableType.clearCache(); CachedIntrospectionResults.clearClassLoader(getClassLoader()); }