public static List<Object> scan(ApplicationContext applicationContext, String... basePackages) { GenericApplicationContext genericAppContext = new GenericApplicationContext(); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(genericAppContext, false); scanner.addIncludeFilter(new AnnotationTypeFilter(RestService.class)); scanner.scan(basePackages); genericAppContext.setParent(applicationContext); genericAppContext.refresh(); List<Object> restResources = new ArrayList<>(genericAppContext.getBeansWithAnnotation(RestService.class).values()); return restResources; }
@Test public void closingChildContextDoesNotCleanUpLoggingSystem() { System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName()); this.initializer.onApplicationEvent( new ApplicationStartedEvent(this.springApplication, new String[0])); TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils.getField(this.initializer, "loggingSystem"); assertThat(loggingSystem.cleanedUp).isFalse(); GenericApplicationContext childContext = new GenericApplicationContext(); childContext.setParent(this.context); this.initializer.onApplicationEvent(new ContextClosedEvent(childContext)); assertThat(loggingSystem.cleanedUp).isFalse(); this.initializer.onApplicationEvent(new ContextClosedEvent(this.context)); assertThat(loggingSystem.cleanedUp).isTrue(); childContext.close(); }