annotate spring-boot-playground/src/main/java/de/comline/spring/application/ExplicitlyConfiguredApplication.java @ 13:a633d0623278

Die Sequenz startet bei 1 und wird auch nur um 1 erhoeht
author Dirk Olmes <dirk.olmes@codedo.de>
date Fri, 14 Aug 2020 08:13:57 +0200
parents 92d52e4ac567
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
1 package de.comline.spring.application;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
2
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
3 import java.util.Arrays;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
4
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
5 import org.springframework.boot.CommandLineRunner;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
6 import org.springframework.boot.SpringApplication;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
7 import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
8 import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
9 import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
10 import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
11 import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
12 import org.springframework.context.ApplicationContext;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
13 import org.springframework.context.annotation.Bean;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
14 import org.springframework.context.annotation.Configuration;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
15 import org.springframework.context.annotation.Import;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
16
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
17 import de.comline.spring.application.ExplicitlyConfiguredApplication.CustomConfig;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
18 import de.comline.spring.controller.HelloController;
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
19
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
20 @Import(CustomConfig.class)
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
21 public class ExplicitlyConfiguredApplication {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
22 public static void main(String[] args) {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
23 SpringApplication.run(ExplicitlyConfiguredApplication.class, args);
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
24 }
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
25
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
26 @Bean
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
27 public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
28 return args -> {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
29 System.out.println("Let's inspect the beans provided by Spring Boot:");
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
30
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
31 String[] beanNames = ctx.getBeanDefinitionNames();
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
32 Arrays.sort(beanNames);
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
33 for (String beanName : beanNames) {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
34 System.out.println(beanName);
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
35 }
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
36 };
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
37 }
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
38
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
39 @Configuration
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
40 // scheint hier nicht zu funktionieren:
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
41 // @ComponentScan(basePackages = "de.comline.spring.controller,de.comline.spring.service")
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
42
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
43 // ServletWebServerFactoryAutoConfiguration for bringing up the embedded tomcat
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
44 // DispatcherServletAutoConfiguration for detecting the REST controllers
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
45 // WebMvcAutoConfiguration enabling Jackson response serialization
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
46 // @formatter:off
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
47 @Import({
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
48 ServletWebServerFactoryAutoConfiguration.class,
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
49 DispatcherServletAutoConfiguration.class,
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
50 JacksonAutoConfiguration.class,
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
51 HttpMessageConvertersAutoConfiguration.class,
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
52 WebMvcAutoConfiguration.class,
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
53
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
54 HelloController.class
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
55 // Note how we do not list the CustomLogicController here, hence the controller is not bound
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
56 })
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
57 // @formatter:on
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
58 static class CustomConfig {
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
59 // no custom methods
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
60 }
92d52e4ac567 JPA hinzugefuegt.
Dirk Olmes <dirk.olmes@codedo.de>
parents:
diff changeset
61 }