Mercurial > hg > SpringPlayground
changeset 1:60afb461bf6c
Import des Spring boot playground
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Tue, 11 Aug 2020 16:08:16 +0200 |
parents | 64e2ebad3366 |
children | 856e646efa17 |
files | spring-boot-playground/pom.xml spring-boot-playground/src/main/java/de/comline/spring/application/Application.java spring-boot-playground/src/main/java/de/comline/spring/controller/CustomLogicController.java spring-boot-playground/src/main/java/de/comline/spring/controller/HelloController.java spring-boot-playground/src/main/java/de/comline/spring/model/json/Greeting.java spring-boot-playground/src/main/java/de/comline/spring/service/CustomLogicService.java |
diffstat | 6 files changed, 201 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.1.13.RELEASE</version> + <relativePath/> + </parent> + <groupId>de.comline</groupId> + <artifactId>spring-boot-playground</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>Spring boot playground</name> + + <properties> + <jdk.version.source>1.8</jdk.version.source> + <jdk.version.target>1.8</jdk.version.target> + <java.version>${jdk.version.source}</java.version> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <verbose>true</verbose> + <source>${jdk.version.source}</source> + <target>${jdk.version.target}</target> + </configuration> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + </exclusion> + </exclusions> + </dependency> +<!-- <dependency> --> +<!-- <groupId>org.junit.jupiter</groupId> --> +<!-- <artifactId>junit-jupiter</artifactId> --> +<!-- <version>5.6.2</version> --> +<!-- <scope>test</scope> --> +<!-- </dependency> --> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <version>2.2</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> \ No newline at end of file
--- /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 + } +}
--- /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(); + } +}
--- /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()); + } +}
--- /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; + } +}
--- /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"; + } +}