WIP
authorKai Moritz <kai@juplo.de>
Fri, 20 Nov 2020 22:22:52 +0000 (23:22 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 20 Nov 2020 22:23:03 +0000 (23:23 +0100)
src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java
src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplicationContextInitializer.java
src/main/resources/META-INF/spring.factories [new file with mode: 0644]

index 7da4fa0..cafcacf 100644 (file)
@@ -7,7 +7,6 @@ import org.springframework.context.annotation.Bean;
 
 @SpringBootApplication
 @EnableConfigurationProperties(MultipleBeansProperties.class)
-@ContextConfiguration()
 public class MultipleBeansApplication {
 
        @Bean(name = "/peter")
index f6d4ecf..02f42a5 100644 (file)
@@ -1,5 +1,6 @@
 package de.juplo.demos.multiplebeans;
 
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.stereotype.Component;
@@ -10,7 +11,12 @@ public class MultipleBeansApplicationContextInitializer
 
     @Override
     public void initialize(ConfigurableApplicationContext context) {
+        context.refresh();
         MultipleBeansProperties properties = context.getBean(MultipleBeansProperties.class);
-        System.out.println(properties.project);
+        ConfigurableListableBeanFactory factory = context.getBeanFactory();
+        for (MultipleBeansProperties.Site site : properties.sites) {
+            SiteController controller = new SiteController(site.name, site.description);
+            factory.registerSingleton("/" + site.name, controller);
+        }
     }
 }
diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories
new file mode 100644 (file)
index 0000000..5c9c458
--- /dev/null
@@ -0,0 +1 @@
+org.springframework.context.ApplicationContextInitializer=de.juplo.demos.multiplebeans.MultipleBeansApplicationContextInitializer