From 3f11bcc2629e5b15483ac40b9bf7b9bbf3ad5657 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 20 Nov 2020 23:22:52 +0100 Subject: [PATCH] WIP --- .../demos/multiplebeans/MultipleBeansApplication.java | 1 - .../MultipleBeansApplicationContextInitializer.java | 8 +++++++- src/main/resources/META-INF/spring.factories | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/META-INF/spring.factories 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 -- 2.20.1