/** * Rebind cas configuration properties. * * @param binder the binder */ public static void rebindCasConfigurationProperties(final ConfigurationPropertiesBindingPostProcessor binder) { Assert.notNull(binder, "Configuration binder cannot be null"); final ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext(); final Map<String, CasConfigurationProperties> map = applicationContext.getBeansOfType(CasConfigurationProperties.class); final String name = map.keySet().iterator().next(); LOGGER.debug("Reloading CAS configuration via [{}]", name); final Object e = applicationContext.getBean(name); binder.postProcessBeforeInitialization(e, name); final Object bean = applicationContext.getAutowireCapableBeanFactory().initializeBean(e, name); applicationContext.getAutowireCapableBeanFactory().autowireBean(bean); LOGGER.debug("Reloaded CAS configuration [{}]", name); }
@Test public void autoConfiguredContext() throws Exception { ApplicationContext context = this.context; assertThat(context.getBean(ExampleSpringBootApplication.class)).isNotNull(); assertThat(context.getBean(ConfigurationPropertiesBindingPostProcessor.class)) .isNotNull(); }
@Test public void disabledAutoConfiguration() throws Exception { ApplicationContext context = this.context; assertThat(context.getBean(ExampleTestConfig.class)).isNotNull(); this.thrown.expect(NoSuchBeanDefinitionException.class); context.getBean(ConfigurationPropertiesBindingPostProcessor.class); }
private void bind(ConfigurableApplicationContext context) { ConfigurationPropertiesBindingPostProcessor post = new ConfigurationPropertiesBindingPostProcessor(); post.setBeanFactory(new DefaultListableBeanFactory()); post.setEnvironment(context.getEnvironment()); post.setApplicationContext(new StaticApplicationContext()); try { post.afterPropertiesSet(); } catch (Exception e) { throw new IllegalStateException("Cannot bind properties", e); } post.postProcessBeforeInitialization(this, getClass().getName()); }