From: Kai Moritz Date: Fri, 20 Nov 2020 22:22:52 +0000 (+0100) Subject: WIP X-Git-Tag: wip-implementation~4 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=3f11bcc2629e5b15483ac40b9bf7b9bbf3ad5657;p=demos%2Fmultiple-beans WIP --- diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java index 7da4fa0..cafcacf 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java @@ -7,7 +7,6 @@ import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableConfigurationProperties(MultipleBeansProperties.class) -@ContextConfiguration() public class MultipleBeansApplication { @Bean(name = "/peter") diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplicationContextInitializer.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplicationContextInitializer.java index f6d4ecf..02f42a5 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplicationContextInitializer.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplicationContextInitializer.java @@ -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 index 0000000..5c9c458 --- /dev/null +++ b/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.context.ApplicationContextInitializer=de.juplo.demos.multiplebeans.MultipleBeansApplicationContextInitializer