changeset 19:fe6a57f7a2cf

Spring Cloud Config server
author Dirk Olmes <dirk.olmes@codedo.de>
date Thu, 17 Sep 2020 17:24:48 +0200
parents 8504317b9a09
children 452cfefb0e1e
files spring-cloud-config-server/.gitignore spring-cloud-config-server/pom.xml spring-cloud-config-server/src/main/java/de/comline/config/application/ConfigServer.java spring-cloud-config-server/src/main/java/de/comline/config/configuration/H2WebConsoleConfig.java spring-cloud-config-server/src/main/resources/application.properties spring-cloud-config-server/src/test/resources/log4j.properties
diffstat 6 files changed, 178 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/.gitignore	Thu Sep 17 17:24:48 2020 +0200
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/pom.xml	Thu Sep 17 17:24:48 2020 +0200
@@ -0,0 +1,115 @@
+<?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-server</artifactId>
+	<version>1.0-SNAPSHOT</version>
+	<packaging>jar</packaging>
+	<name>Spring Cloud Config Server</name>
+	<url>http://www.comline.de</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.cloud</groupId>
+			<artifactId>spring-cloud-config-server</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>org.eclipse.jgit</groupId>
+					<artifactId>org.eclipse.jgit</artifactId>
+				</exclusion>
+				<exclusion>
+					<groupId>org.eclipse.jgit</groupId>
+					<artifactId>org.eclipse.jgit.http.apache</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<!-- this is a transitive dependency of jgit. The server won't start without jsch, though -->
+		<dependency>
+			<groupId>com.jcraft</groupId>
+			<artifactId>jsch</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.data</groupId>
+			<artifactId>spring-data-jdbc</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.zaxxer</groupId>
+			<artifactId>HikariCP</artifactId>
+		</dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</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>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/src/main/java/de/comline/config/application/ConfigServer.java	Thu Sep 17 17:24:48 2020 +0200
@@ -0,0 +1,17 @@
+package de.comline.config.application;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.config.server.EnableConfigServer;
+import org.springframework.context.annotation.Import;
+
+import de.comline.config.configuration.H2WebConsoleConfig;
+
+@SpringBootApplication
+@EnableConfigServer
+@Import(H2WebConsoleConfig.class)
+public class ConfigServer {
+	public static void main(String[] args) {
+		SpringApplication.run(ConfigServer.class, args);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/src/main/java/de/comline/config/configuration/H2WebConsoleConfig.java	Thu Sep 17 17:24:48 2020 +0200
@@ -0,0 +1,20 @@
+package de.comline.config.configuration;
+
+import org.h2.tools.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class H2WebConsoleConfig {
+	private static final Logger LOG = LoggerFactory.getLogger(H2WebConsoleConfig.class);
+
+	@Bean(name = "h2WebConsole", initMethod = "start", destroyMethod = "stop")
+	public Server buildServer() throws Exception {
+		String port = "8081";
+
+		LOG.info("H2 web console server listening on port " + port);
+		return Server.createWebServer("-web", "-webAllowOthers", "-webPort", port);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/src/main/resources/application.properties	Thu Sep 17 17:24:48 2020 +0200
@@ -0,0 +1,15 @@
+#debug = true 
+
+logging.pattern.console = %d{HH:mm:ss.SSS} %-5p [%10.10t] %c{1} : %m%n
+
+server.port = 8888
+
+spring.application.name = spring-cloud-config-server
+
+spring.cloud.config.server.jdbc.bootstrap = true
+spring.cloud.config.server.git.enabled = false
+
+spring.datasource.url = jdbc:h2:./target/db/config;AUTO_SERVER=true
+
+spring.main.banner-mode = off
+spring.profiles.active = jdbc
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spring-cloud-config-server/src/test/resources/log4j.properties	Thu Sep 17 17:24:48 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