+++ /dev/null
-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);
- }
- }
-}
+++ /dev/null
-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;
- }
-}
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
--- /dev/null
+<!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>