From: Kai Moritz Date: Fri, 20 Nov 2020 21:19:22 +0000 (+0100) Subject: WIP X-Git-Tag: wip-implementation~6 X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=194a62c54c4e6bba63e706e648b427182106dbdb;p=demos%2Fmultiple-beans WIP --- 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/site.html b/src/main/resources/templates/site.html new file mode 100644 index 0000000..2b66bb5 --- /dev/null +++ b/src/main/resources/templates/site.html @@ -0,0 +1,22 @@ + + + + SITE-TEMPLATE + + + + +

SITE

+
+

DESCRIPTION

+
+
+

+ + Each site is defined in the configuration with name and description inside an array. + This demo shows, how to create multiple beans of the same type based on the configuration. + +

+
+ + diff --git a/src/main/resources/templates/view.html b/src/main/resources/templates/view.html deleted file mode 100644 index 2b66bb5..0000000 --- a/src/main/resources/templates/view.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - SITE-TEMPLATE - - - - -

SITE

-
-

DESCRIPTION

-
-
-

- - Each site is defined in the configuration with name and description inside an array. - This demo shows, how to create multiple beans of the same type based on the configuration. - -

-
- -