<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.webjars</groupId>
+ <artifactId>bootstrap</artifactId>
+ <version>4.5.2</version>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
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);
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 {
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)
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
-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
--- /dev/null
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org" th:replace="~{layout :: pagelayout(~{:: title}, ~{:: h1}, ~{:: div.card-text})}">
+ <head>
+ <title th:text="${name}">SITE-TEMPLATE</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 th:text="${name}">SITE</h1>
+ <div class="card-text">
+ <p th:text="${description}">DESCRIPTION</p>
+ </div>
+ <div class="card-text">
+ <p>
+ <em>
+ 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.
+ </em>
+ </p>
+ </div>
+ </body>
+</html>
+++ /dev/null
-<!DOCTYPE HTML>
-<html xmlns:th="http://www.thymeleaf.org" th:replace="~{layout :: pagelayout(~{:: title}, ~{:: h1}, ~{:: div.card-text})}">
- <head>
- <title th:text="${name}">SITE-TEMPLATE</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 th:text="${name}">SITE</h1>
- <div class="card-text">
- <p th:text="${description}">DESCRIPTION</p>
- </div>
- <div class="card-text">
- <p>
- <em>
- 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.
- </em>
- </p>
- </div>
- </body>
-</html>