WIP
authorKai Moritz <kai@juplo.de>
Fri, 20 Nov 2020 23:39:54 +0000 (00:39 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 20 Nov 2020 23:39:54 +0000 (00:39 +0100)
src/main/java/de/juplo/demos/multiplebeans/HomeController.java [new file with mode: 0644]
src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java [deleted file]
src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java [deleted file]
src/main/resources/application.yml
src/main/resources/templates/home.html [new file with mode: 0644]

diff --git a/src/main/java/de/juplo/demos/multiplebeans/HomeController.java b/src/main/java/de/juplo/demos/multiplebeans/HomeController.java
new file mode 100644 (file)
index 0000000..2645129
--- /dev/null
@@ -0,0 +1,2 @@
+package de.juplo.demos.multiplebeans;public class HomeController {
+}
diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansBeanFactoryPostProcessor.java
deleted file mode 100644 (file)
index 50bbbc7..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-package de.juplo.demos.multiplebeans;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.stereotype.Component;
-
-public class MultipleBeansBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
-
-    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
-
-        MultipleBeansProperties properties = factory.getBean(MultipleBeansProperties.class);
-        BeanDefinitionRegistry registry = (BeanDefinitionRegistry)factory;
-
-        for (MultipleBeansProperties.Site site : properties.sites) {
-            BeanDefinition beanDefinition =
-                    BeanDefinitionBuilder
-                            .genericBeanDefinition(SiteController.class)
-                            .addConstructorArgValue(site.name)
-                            .addConstructorArgValue(site.description)
-                            .getBeanDefinition();
-
-            registry.registerBeanDefinition("name", beanDefinition);
-        }
-    }
-}
diff --git a/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java b/src/main/java/de/juplo/demos/multiplebeans/MultipleBeansProperties.java
deleted file mode 100644 (file)
index 5d1e2fd..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package de.juplo.demos.multiplebeans;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties("juplo")
-@Getter
-@Setter
-public class MultipleBeansProperties {
-
-    String project;
-    Site[] sites;
-
-
-    @Getter
-    @Setter
-    public static class Site {
-
-        String name;
-        String description;
-    }
-}
index 87bec8d..01ec1b0 100644 (file)
@@ -1,9 +1,2 @@
 juplo:
-  project: multiple-beans
-  sites:
-    - 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!
+  sites: peter, ute, franz
diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html
new file mode 100644 (file)
index 0000000..e2b7b4f
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org" th:replace="~{layout :: pagelayout(~{:: title}, ~{:: h1}, ~{:: div.card-text})}">
+  <head>
+    <title>Home</title>
+    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+  </head>
+  <body>
+    <h1>Home</h1>
+    <div class="card-text">
+      <ul>
+        <li th:each="site : ${sites}">
+          <a href="#" th:href="@{'/' + ${site}}" th:text="${site}">SITE</a>
+        </li>
+      </ul>
+    </div>
+    <div class="card-text">
+      <p>
+        <em>
+          This page links to the pages, that are served by the dynamically created beans.
+        </em>
+      </p>
+    </div>
+  </body>
+</html>