# HG changeset patch # User Dirk Olmes # Date 1597154896 -7200 # Node ID 60afb461bf6cb16ac8da8d4b4e0e3d495447a258 # Parent 64e2ebad33667a83d9bedfe669d0df3ecd68d631 Import des Spring boot playground diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/pom.xml Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,70 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.13.RELEASE + + + de.comline + spring-boot-playground + 0.0.1-SNAPSHOT + Spring boot playground + + + 1.8 + 1.8 + ${jdk.version.source} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + ${jdk.version.source} + ${jdk.version.target} + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + + + org.hamcrest + hamcrest + 2.2 + test + + + \ No newline at end of file diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/src/main/java/de/comline/spring/application/Application.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/src/main/java/de/comline/spring/application/Application.java Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,68 @@ +package de.comline.spring.application; + +import java.util.Arrays; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import de.comline.spring.application.Application.CustomConfig; +import de.comline.spring.controller.CustomLogicController; +import de.comline.spring.controller.HelloController; +import de.comline.spring.service.CustomLogicService; + +//@SpringBootApplication + +//@ComponentScan(basePackages = "de.comline.spring.controller,de.comline.spring.service") +//@EnableAutoConfiguration + +@Import(CustomConfig.class) +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Bean + public CommandLineRunner commandLineRunner(ApplicationContext ctx) { + return args -> { + System.out.println("Let's inspect the beans provided by Spring Boot:"); + + String[] beanNames = ctx.getBeanDefinitionNames(); + Arrays.sort(beanNames); + for (String beanName : beanNames) { + System.out.println(beanName); + } + }; + } + + @Configuration + // scheint hier nicht zu funktionieren: + // @ComponentScan(basePackages = "de.comline.spring.controller,de.comline.spring.service") + + // ServletWebServerFactoryAutoConfiguration for bringing up the embedded tomcat + // DispatcherServletAutoConfiguration for detecting the REST controllers + // @formatter:off + @Import({ + ServletWebServerFactoryAutoConfiguration.class, + DispatcherServletAutoConfiguration.class, + JacksonAutoConfiguration.class, + HttpMessageConvertersAutoConfiguration.class, +// HttpEncodingAutoConfiguration.class, +// CodecsAutoConfiguration.class, + + HelloController.class, + CustomLogicController.class, + CustomLogicService.class + }) + // @formatter:on + static class CustomConfig { + // no custom methods + } +} diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/src/main/java/de/comline/spring/controller/CustomLogicController.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/src/main/java/de/comline/spring/controller/CustomLogicController.java Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,18 @@ +package de.comline.spring.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.comline.spring.service.CustomLogicService; + +@RestController +public class CustomLogicController { + @Autowired + private CustomLogicService service; + + @RequestMapping("/svc") + public String getCustomLogic() { + return service.doit(); + } +} diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/src/main/java/de/comline/spring/controller/HelloController.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/src/main/java/de/comline/spring/controller/HelloController.java Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,19 @@ +package de.comline.spring.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import de.comline.spring.model.json.Greeting; + +@RestController +public class HelloController { + @RequestMapping("/") + public String index() { + return "Greetings from Spring Boot!\n"; + } + + @RequestMapping(path = "/", consumes = "application/json", produces = "application/json") + public Greeting sayHello() { + return new Greeting(index()); + } +} diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/src/main/java/de/comline/spring/model/json/Greeting.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/src/main/java/de/comline/spring/model/json/Greeting.java Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,16 @@ +package de.comline.spring.model.json; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Greeting { + @JsonProperty("msg") + private String message; + + public Greeting(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} diff -r 64e2ebad3366 -r 60afb461bf6c spring-boot-playground/src/main/java/de/comline/spring/service/CustomLogicService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-boot-playground/src/main/java/de/comline/spring/service/CustomLogicService.java Tue Aug 11 16:08:16 2020 +0200 @@ -0,0 +1,10 @@ +package de.comline.spring.service; + +import org.springframework.stereotype.Service; + +@Service +public class CustomLogicService { + public String doit() { + return "this is the custom logic"; + } +}