From 6c8507d73eec12bfdcb50fe25b640a819f0ed35d Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 17 Dec 2015 21:21:08 +0000 Subject: [PATCH] Add simple configserver --- .../BootstrapDecryptionClientApplication.java | 14 ++- .../src/main/resources/application.yml | 2 + configserver/pom.xml | 108 ++++++++++++++++++ configserver/src/main/config/application.yml | 0 .../java/demo/ConfigServerApplication.java | 15 +++ .../src/main/resources/application.yml | 19 +++ .../demo/ConfigServerApplicationTests.java | 20 ++++ pom.xml | 1 + 8 files changed, 175 insertions(+), 4 deletions(-) create mode 100644 configserver/pom.xml create mode 100644 configserver/src/main/config/application.yml create mode 100644 configserver/src/main/java/demo/ConfigServerApplication.java create mode 100644 configserver/src/main/resources/application.yml create mode 100644 configserver/src/test/java/demo/ConfigServerApplicationTests.java diff --git a/config-client-decrypt/src/main/java/demo/BootstrapDecryptionClientApplication.java b/config-client-decrypt/src/main/java/demo/BootstrapDecryptionClientApplication.java index 9cf4ada..a6485d3 100644 --- a/config-client-decrypt/src/main/java/demo/BootstrapDecryptionClientApplication.java +++ b/config-client-decrypt/src/main/java/demo/BootstrapDecryptionClientApplication.java @@ -7,21 +7,27 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.client.ConfigClientProperties; +import org.springframework.core.env.Environment; /** * @author Dave Syer */ @SpringBootApplication public class BootstrapDecryptionClientApplication implements CommandLineRunner { - + private static Log logger = LogFactory.getLog(BootstrapDecryptionClientApplication.class); - + @Autowired private ConfigClientProperties config; - + + @Autowired + private Environment environment; + @Override public void run(String... args) throws Exception { - logger.info("Config Server URI: " + config.getUri()); + logger.info("Config Server URI: " + this.config.getUri()); + logger.info("And info.bar: " + this.environment.getProperty("info.bar")); + logger.info("And info.spam: " + this.environment.getProperty("info.spam")); } public static void main(String[] args) { diff --git a/config-client-decrypt/src/main/resources/application.yml b/config-client-decrypt/src/main/resources/application.yml index ee2a629..2cda84e 100644 --- a/config-client-decrypt/src/main/resources/application.yml +++ b/config-client-decrypt/src/main/resources/application.yml @@ -1,3 +1,5 @@ spring: application: name: client +info: + bar: '{cipher}db63f1b828044c38f9fab4cbe4cd2ad508380399e184691902b3c44a38e5189f' \ No newline at end of file diff --git a/configserver/pom.xml b/configserver/pom.xml new file mode 100644 index 0000000..04348b8 --- /dev/null +++ b/configserver/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-sample-configserver + Brixton.BUILD-SNAPSHOT + jar + + spring-cloud-sample-configserver + Demo project for Spring Cloud + + + org.springframework.cloud + spring-cloud-starter-parent + Brixton.BUILD-SNAPSHOT + + + + + UTF-8 + demo.DemoApplication + 1.7 + + + + + org.springframework.cloud + spring-cloud-config-server + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + maven-deploy-plugin + + true + + + + + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + http://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/libs-snapshot-local + + true + + + + spring-milestones + Spring Milestones + http://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + http://repo.spring.io/release + + false + + + + + diff --git a/configserver/src/main/config/application.yml b/configserver/src/main/config/application.yml new file mode 100644 index 0000000..e69de29 diff --git a/configserver/src/main/java/demo/ConfigServerApplication.java b/configserver/src/main/java/demo/ConfigServerApplication.java new file mode 100644 index 0000000..98cb9f3 --- /dev/null +++ b/configserver/src/main/java/demo/ConfigServerApplication.java @@ -0,0 +1,15 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + +@SpringBootApplication +@EnableConfigServer +public class ConfigServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ConfigServerApplication.class, args); + } + +} diff --git a/configserver/src/main/resources/application.yml b/configserver/src/main/resources/application.yml new file mode 100644 index 0000000..bb01812 --- /dev/null +++ b/configserver/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: 8888 + +encrypt: + key: ${SECRET_KEY:foo} # normally this would be an environment variable + +spring: + application: + name: configserver + cloud: + config: + server: + bootstrap: true + git: + uri: https://github.com/spring-cloud-samples/config-repo + encrypt: + enabled: false + overrides: + info.bar: '\{cipher}762c11829d517b203ac94a0180f1950b133b83cde34296549d8fed611a9b2fb5' diff --git a/configserver/src/test/java/demo/ConfigServerApplicationTests.java b/configserver/src/test/java/demo/ConfigServerApplicationTests.java new file mode 100644 index 0000000..55a4328 --- /dev/null +++ b/configserver/src/test/java/demo/ConfigServerApplicationTests.java @@ -0,0 +1,20 @@ +package demo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = ConfigServerApplication.class) +@WebAppConfiguration +@DirtiesContext +public class ConfigServerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/pom.xml b/pom.xml index 1e85cc6..06ca6d3 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ config-client config-client-decrypt config-retry + configserver configserver-bootstrap configserver-eureka eureka-first