4
|
1 package de.comline.spring.application;
|
|
2
|
|
3 import java.util.Arrays;
|
|
4
|
|
5 import org.springframework.boot.CommandLineRunner;
|
|
6 import org.springframework.boot.SpringApplication;
|
|
7 import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
|
8 import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
|
9 import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
|
10 import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
|
11 import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
|
12 import org.springframework.context.ApplicationContext;
|
|
13 import org.springframework.context.annotation.Bean;
|
|
14 import org.springframework.context.annotation.Configuration;
|
|
15 import org.springframework.context.annotation.Import;
|
|
16
|
|
17 import de.comline.spring.application.ExplicitlyConfiguredApplication.CustomConfig;
|
|
18 import de.comline.spring.controller.HelloController;
|
|
19
|
|
20 @Import(CustomConfig.class)
|
|
21 public class ExplicitlyConfiguredApplication {
|
|
22 public static void main(String[] args) {
|
|
23 SpringApplication.run(ExplicitlyConfiguredApplication.class, args);
|
|
24 }
|
|
25
|
|
26 @Bean
|
|
27 public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
|
28 return args -> {
|
|
29 System.out.println("Let's inspect the beans provided by Spring Boot:");
|
|
30
|
|
31 String[] beanNames = ctx.getBeanDefinitionNames();
|
|
32 Arrays.sort(beanNames);
|
|
33 for (String beanName : beanNames) {
|
|
34 System.out.println(beanName);
|
|
35 }
|
|
36 };
|
|
37 }
|
|
38
|
|
39 @Configuration
|
|
40 // scheint hier nicht zu funktionieren:
|
|
41 // @ComponentScan(basePackages = "de.comline.spring.controller,de.comline.spring.service")
|
|
42
|
|
43 // ServletWebServerFactoryAutoConfiguration for bringing up the embedded tomcat
|
|
44 // DispatcherServletAutoConfiguration for detecting the REST controllers
|
|
45 // WebMvcAutoConfiguration enabling Jackson response serialization
|
|
46 // @formatter:off
|
|
47 @Import({
|
|
48 ServletWebServerFactoryAutoConfiguration.class,
|
|
49 DispatcherServletAutoConfiguration.class,
|
|
50 JacksonAutoConfiguration.class,
|
|
51 HttpMessageConvertersAutoConfiguration.class,
|
|
52 WebMvcAutoConfiguration.class,
|
|
53
|
|
54 HelloController.class
|
|
55 // Note how we do not list the CustomLogicController here, hence the controller is not bound
|
|
56 })
|
|
57 // @formatter:on
|
|
58 static class CustomConfig {
|
|
59 // no custom methods
|
|
60 }
|
|
61 }
|