Mercurial > hg > SpringPlayground
changeset 20:452cfefb0e1e default tip
Einfache Spring Application, die ihre config aus dem Spring Cloud Config Server liest
author | Dirk Olmes <dirk.olmes@codedo.de> |
---|---|
date | Thu, 17 Sep 2020 17:25:15 +0200 |
parents | fe6a57f7a2cf |
children | |
files | spring-cloud-config-client/.gitignore spring-cloud-config-client/pom.xml spring-cloud-config-client/src/main/java/de/comline/config/application/ConfigClient.java spring-cloud-config-client/src/main/java/de/comline/config/controller/HelloController.java spring-cloud-config-client/src/main/resources/application.properties spring-cloud-config-client/src/test/resources/log4j.properties |
diffstat | 6 files changed, 134 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/.gitignore Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,4 @@ +.classpath +.project +.settings +target
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/pom.xml Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>de.comline</groupId> + <artifactId>spring-cloud-config-client</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>new project</name> + <url>http://maven.apache.org</url> + + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.3.3.RELEASE</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-dependencies</artifactId> + <version>Hoxton.SR8</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-config-client</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <encoding>${project.build.sourceEncoding}</encoding> + <source>${maven.compiler.source}</source> + <target>${maven.compiler.target}</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>3.0.0-M5</version> + <configuration> + <!-- produce large stack traces in case something goes wrong for better debugging from the logs --> + <trimStackTrace>false</trimStackTrace> + <!-- dump the info right into the logfile instead of into separate files --> + <useFile>false</useFile> + </configuration> + </plugin> + </plugins> + </build> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/src/main/java/de/comline/config/application/ConfigClient.java Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,15 @@ +package de.comline.config.application; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Import; + +import de.comline.config.controller.HelloController; + +@SpringBootApplication +@Import(HelloController.class) +public class ConfigClient { + public static void main(String[] args) { + SpringApplication.run(ConfigClient.class, args); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/src/main/java/de/comline/config/controller/HelloController.java Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,16 @@ +package de.comline.config.controller; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + @Value("${greeting:ERROR - No greeting configured}") + private String greeting; + + @RequestMapping("/") + public String index() { + return greeting; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/src/main/resources/application.properties Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,7 @@ +#debug = true + +logging.pattern.console = %d{HH:mm:ss.SSS} %-5p [%10.10t] %c{1} : %m%n + +spring.application.name = foo + +spring.main.banner-mode = off
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spring-cloud-config-client/src/test/resources/log4j.properties Thu Sep 17 17:25:15 2020 +0200 @@ -0,0 +1,7 @@ + +# The usual stuff. Note that A1 is configured in root, not separately +log4j.rootCategory = DEBUG, A1 +log4j.appender.A1 = org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout = org.apache.log4j.PatternLayout +#log4j.appender.A1.layout.ConversionPattern = %d{MMM dd HH:mm:ss} [%t] %p %c - %m%n +log4j.appender.A1.layout.ConversionPattern = %c{1} - %m%n