@Bean public Properties propertyFactory() throws IOException { List<Resource> resources = loadPropertyResource(); PropertiesFactoryBean factory = new PropertiesFactoryBean(); factory.setLocations(resources.toArray(new Resource[resources.size()])); factory.afterPropertiesSet(); Properties props = factory.getObject(); new ConfigAccessor().get() .getProperties() .stream() .forEach(e -> { if (props.getProperty(e._1()) == null) { props.put(e._1(), e._2()); } }); System.getProperties() .entrySet() .forEach(e -> props.put(e.getKey(), e.getValue())); return props; }
@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; }
@Test public void properties() { assertThat(configurer.buildConfig(MicroserverConfigurerTest.class).getProperties().stream().map(Tuple2::_1).toSet(), hasItem("hello")); assertThat(configurer.buildConfig(MicroserverConfigurerTest.class).getProperties().stream().map(Tuple2::_2).toSet(), hasItem("world")); }
default boolean allMatch(Predicate<? super Tuple2<K,V>> c){ return !stream().filterNot(c) .findFirst() .isPresent(); } default boolean equalTo(PersistentMap<K,V> map){
@Override public Set<Entry<K, V>> entrySet() { return host.stream() .map(t2->new AbstractMap.SimpleEntry<>(t2._1(),t2._2())) .collect(Collectors.toSet()); }
public static <K,V> TreeMap<K,V> fromMap(Comparator<K> comp, PersistentMap<K,V> map){ if(map instanceof TreeMap){ TreeMap<K,V> t = (TreeMap)map; return t.withComparator(comp); } return new TreeMap<>(RedBlackTree.fromStream(comp,map.stream()),comp); }
@Override public TrieMap<K, V> putAll(PersistentMap<? extends K,? extends V> map) { return map.stream().foldLeft(this,(m,next)->m.put(next._1(),next._2())); }
@Override public TreeMap<K, V> putAll(PersistentMap<? extends K, ? extends V> map) { return map.stream().foldLeft(this,(m,next)->m.put(next._1(),next._2())); }
default boolean allMatch(Predicate<? super Tuple2<K,V>> c){ return !stream().filterNot(c) .findFirst() .isPresent(); } default boolean equalTo(PersistentMap<K,V> map){
@Override public Set<Entry<K, V>> entrySet() { return host.stream() .map(t2->new AbstractMap.SimpleEntry<>(t2._1(),t2._2())) .collect(Collectors.toSet()); }
public static <K,V> TreeMap<K,V> fromMap(Comparator<K> comp, PersistentMap<K,V> map){ if(map instanceof TreeMap){ TreeMap<K,V> t = (TreeMap)map; return t.withComparator(comp); } return new TreeMap<>(RedBlackTree.fromStream(comp,map.stream()),comp); }
@Bean public Properties propertyFactory() throws IOException { List<Resource> resources = loadPropertyResource(); PropertiesFactoryBean factory = new PropertiesFactoryBean(); factory.setLocations(resources.toArray(new Resource[resources.size()])); factory.afterPropertiesSet(); Properties props = factory.getObject(); new ConfigAccessor().get() .getProperties() .stream() .forEach(e -> { if (props.getProperty(e._1()) == null) { props.put(e._1(), e._2()); } }); System.getProperties() .entrySet() .forEach(e -> props.put(e.getKey(), e.getValue())); return props; }
@Override public TrieMap<K, V> putAll(PersistentMap<? extends K,? extends V> map) { return map.stream().foldLeft(this,(m,next)->m.put(next._1(),next._2())); }
@Override public TreeMap<K, V> putAll(PersistentMap<? extends K, ? extends V> map) { return map.stream().foldLeft(this,(m,next)->m.put(next._1(),next._2())); }
@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; }