@Test public void testStaticApplicationContextMessageSourceWithStaticParent() { StaticApplicationContext ac = new StaticApplicationContext(); StaticApplicationContext parent = new StaticApplicationContext(); parent.refresh(); ac.setParent(parent); ac.refresh(); assertEquals("default", ac.getMessage("code1", null, "default", Locale.ENGLISH)); assertEquals("default value", ac.getMessage("code1", new Object[] {"value"}, "default {0}", Locale.ENGLISH)); }
@Test public void testStaticApplicationContextMessageSourceWithDefaultParent() { StaticApplicationContext ac = new StaticApplicationContext(); GenericApplicationContext parent = new GenericApplicationContext(); parent.refresh(); ac.setParent(parent); ac.refresh(); assertEquals("default", ac.getMessage("code1", null, "default", Locale.ENGLISH)); assertEquals("default value", ac.getMessage("code1", new Object[] {"value"}, "default {0}", Locale.ENGLISH)); }
StaticApplicationContext parent = new StaticApplicationContext(); parent.refresh(); ac.setParent(parent);
/** * {@inheritDoc} * <p>The parent {@linkplain #getEnvironment() environment} is * delegated to this (child) context if the parent is a * {@link org.springframework.context.ConfigurableApplicationContext} implementation. * <p>The parent {@linkplain #getServletContext() servlet context} is * delegated to this (child) context if the parent is a {@link WebApplicationContext} * implementation. */ @Override public void setParent(ApplicationContext parent) { super.setParent(parent); if (parent instanceof WebApplicationContext) { this.servletContext = ((WebApplicationContext) parent).getServletContext(); } }
/** * {@inheritDoc} * <p>The parent {@linkplain #getEnvironment() environment} is * delegated to this (child) context if the parent is a * {@link ConfigurableApplicationContext} implementation. * <p>The parent {@linkplain #getServletContext() servlet context} is * delegated to this (child) context if the parent is a {@link WebApplicationContext} * implementation. */ @Override public void setParent(ApplicationContext parent) { super.setParent(parent); if (parent instanceof WebApplicationContext) { this.servletContext = ((WebApplicationContext) parent).getServletContext(); } }
private void maybeSetBeanFactory(ConfigurableApplicationContext context, ConfigurationPropertiesBindingPostProcessor post) { StaticApplicationContext other = new StaticApplicationContext(); other.setEnvironment(context.getEnvironment()); other.registerSingleton(ConfigurationBeanFactoryMetadata.class.getName(), ConfigurationBeanFactoryMetadata.class); other.setParent(context); post.setApplicationContext(other); }