From 194a62c54c4e6bba63e706e648b427182106dbdb Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 20 Nov 2020 22:19:22 +0100 Subject: [PATCH] WIP --- pom.xml | 6 ++++++ .../multiplebeans/MultipleBeansApplication.java | 5 +++++ .../MultipleBeansBeanFactoryPostProcessor.java | 3 +-- .../multiplebeans/MultipleBeansProperties.java | 5 +++-- src/main/resources/application.yml | 14 +++++--------- .../resources/templates/{view.html => site.html} | 0 6 files changed, 20 insertions(+), 13 deletions(-) rename src/main/resources/templates/{view.html => site.html} (100%) diff --git a/pom.xml b/pom.xml index c5a9621..0c9e4dc 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,12 @@ lombok true + + org.webjars + bootstrap + 4.5.2 + runtime + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java index 97cfb2a..cafcacf 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansApplication.java @@ -3,11 +3,16 @@ package de.juplo.demos.multiplebeans; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableConfigurationProperties(MultipleBeansProperties.class) public class MultipleBeansApplication { + @Bean(name = "/peter") + public SiteController controller(MultipleBeansProperties properties) { + return new SiteController(properties.sites[0].name, properties.sites[0].description); + } public static void main(String[] args) { SpringApplication.run(MultipleBeansApplication.class, args); diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java index 0a89bcc..50bbbc7 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.stereotype.Component; -@Component public class MultipleBeansBeanFactoryPostProcessor implements BeanFactoryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException { @@ -16,7 +15,7 @@ public class MultipleBeansBeanFactoryPostProcessor implements BeanFactoryPostPro MultipleBeansProperties properties = factory.getBean(MultipleBeansProperties.class); BeanDefinitionRegistry registry = (BeanDefinitionRegistry)factory; - for (MultipleBeansProperties.Site site : properties.site) { + for (MultipleBeansProperties.Site site : properties.sites) { BeanDefinition beanDefinition = BeanDefinitionBuilder .genericBeanDefinition(SiteController.class) diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java index f8384ff..5d1e2fd 100644 --- a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java +++ b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java @@ -4,12 +4,13 @@ import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; -@ConfigurationProperties("de.juplo") +@ConfigurationProperties("juplo") @Getter @Setter public class MultipleBeansProperties { - Site[] site; + String project; + Site[] sites; @Getter diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1f49f99..04397c1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,10 +1,6 @@ -de: - juplo: - site: - - name: peter - description: This is the Home-Page of PETER - - name: ute - description: My name is Ute. I like cats! - - name: franz - description: Franz was here! +juplo: + project: multiple-beans + sites: + - name: peter + description: This is the Home-Page of PETER diff --git a/src/main/resources/templates/view.html b/src/main/resources/templates/site.html similarity index 100% rename from src/main/resources/templates/view.html rename to src/main/resources/templates/site.html -- 2.20.1