/** * Do nothing: We hold a single internal BeanFactory and rely on callers * to register beans through our public methods (or the BeanFactory's). * @see #registerBeanDefinition */ @Override protected final void refreshBeanFactory() throws IllegalStateException { if (!this.refreshed.compareAndSet(false, true)) { throw new IllegalStateException( "GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once"); } this.beanFactory.setSerializationId(getId()); }
/** * Do nothing: We hold a single internal BeanFactory and rely on callers * to register beans through our public methods (or the BeanFactory's). * @see #registerBeanDefinition */ @Override protected final void refreshBeanFactory() throws IllegalStateException { if (!this.refreshed.compareAndSet(false, true)) { throw new IllegalStateException( "GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once"); } this.beanFactory.setSerializationId(getId()); }
@Test public void testGenericApplicationContextWithXmlBeanDefinitionsAndSpecifiedId() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setId("testContext"); ctx.setDisplayName("Test Context"); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertEquals("testContext", ctx.getId()); assertEquals("Test Context", ctx.getDisplayName()); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); ctx.close(); }
@Test public void testGenericApplicationContextWithXmlBeanDefinitionsAndClassLoaderNull() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader(null); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_B, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_C, getClass())); reader.loadBeanDefinitions(new ClassPathResource(CONTEXT_A, getClass())); ctx.refresh(); assertEquals(ObjectUtils.identityToString(ctx), ctx.getId()); assertEquals(ObjectUtils.identityToString(ctx), ctx.getDisplayName()); assertTrue(ctx.containsBean("service")); assertTrue(ctx.containsBean("logicOne")); assertTrue(ctx.containsBean("logicTwo")); ctx.close(); }
/** * Do nothing: We hold a single internal BeanFactory and rely on callers * to register beans through our public methods (or the BeanFactory's). * @see #registerBeanDefinition */ @Override protected final void refreshBeanFactory() throws IllegalStateException { if (!this.refreshed.compareAndSet(false, true)) { throw new IllegalStateException( "GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once"); } this.beanFactory.setSerializationId(getId()); }