@Override public ConfigurableApplicationContext createSpringApp(Config config, Class... classes) { logger.debug("Configuring Spring"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.setAllowCircularReferences(config.isAllowCircularReferences()); rootContext.register(classes); rootContext.scan(config.getBasePackages()); rootContext.refresh(); logger.debug("Configuring Additional Spring Beans"); ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) rootContext).getBeanFactory(); config.getDataSources() .stream() .map(Tuple2::_1) .filter(it -> !new ConfigAccessor().get() .getDefaultDataSourceName() .equals(it)) .forEach(name -> { List<SpringDBConfig> dbConfig = getConfig(config, rootContext, beanFactory); dbConfig.forEach(spring -> spring.createSpringApp(name)); }); logger.debug("Finished Configuring Spring"); return rootContext; }
private void loadConfig(Class<?>... configs) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setAllowCircularReferences(false); context.register(configs); context.setServletContext(new MockServletContext()); context.refresh(); } }
@Override public ConfigurableApplicationContext createSpringApp(Config config, Class... classes) { logger.debug("Configuring Spring"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.setAllowCircularReferences(config.isAllowCircularReferences()); rootContext.register(classes); rootContext.scan(config.getBasePackages()); rootContext.refresh(); logger.debug("Configuring Additional Spring Beans"); ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) rootContext).getBeanFactory(); config.getDataSources() .stream() .map(Tuple2::_1) .filter(it -> !new ConfigAccessor().get() .getDefaultDataSourceName() .equals(it)) .forEach(name -> { List<SpringDBConfig> dbConfig = getConfig(config, rootContext, beanFactory); dbConfig.forEach(spring -> spring.createSpringApp(name)); }); logger.debug("Finished Configuring Spring"); return rootContext; }
context.setId(testContext.getName()); context.setAllowBeanDefinitionOverriding(true); context.setAllowCircularReferences(false);
configuredContext.setId(testContext.getName()); configuredContext.setDisplayName(testContext.getName()); configuredContext.setAllowCircularReferences(false); configuredContext.setAllowBeanDefinitionOverriding(true);