[BAEL-2116]

This commit is contained in:
Philippe
2018-09-02 16:33:11 -03:00
913 changed files with 14178 additions and 4393 deletions

View File

@@ -31,6 +31,7 @@
<module>spring-cloud-zuul-eureka-integration</module>
<module>spring-cloud-contract</module>
<module>spring-cloud-kubernetes</module>
<module>spring-cloud-archaius</module>
<module>spring-cloud-vault</module>
</modules>

View File

@@ -0,0 +1,14 @@
# Spring Cloud Archaius
#### Basic Config
This service has the basic, out-of-the-box Spring Cloud Netflix Archaius configuration.
#### Extra Configs
This service customizes some properties supported by Archaius.
These properties are set up on the main method, since Archaius uses System properties, but they could be added as command line arguments when launching the app.
#### Additional Sources
In this service we create a new AbstractConfiguration bean, setting up a new Configuration Properties source.
These properties have precedence over all the other properties in the Archaius Composite Configuration.

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>additional-sources-simple</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>additional-sources-simple</name>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-archaius</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,13 @@
package com.baeldung.spring.cloud.archaius.additionalsources;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AdditionalSourcesSimpleApplication {
public static void main(String[] args) {
SpringApplication.run(AdditionalSourcesSimpleApplication.class, args);
}
}

View File

@@ -0,0 +1,21 @@
package com.baeldung.spring.cloud.archaius.additionalsources.config;
import org.apache.commons.configuration.AbstractConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.config.DynamicConfiguration;
import com.netflix.config.FixedDelayPollingScheduler;
import com.netflix.config.PolledConfigurationSource;
import com.netflix.config.sources.URLConfigurationSource;
@Configuration
public class ApplicationPropertiesConfigurations {
@Bean
public AbstractConfiguration addApplicationPropertiesSource() {
PolledConfigurationSource source = new URLConfigurationSource("classpath:other-config.properties");
return new DynamicConfiguration(source, new FixedDelayPollingScheduler());
}
}

View File

@@ -0,0 +1,37 @@
package com.baeldung.spring.cloud.archaius.additionalsources.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
@RestController
public class ConfigPropertiesController {
private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.one", "not found!");
private DynamicStringProperty propertyTwoWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.two", "not found!");
private DynamicStringProperty propertyThreeWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.three", "not found!");
private DynamicStringProperty propertyFourWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.four", "not found!");
@GetMapping("/properties-from-dynamic")
public Map<String, String> getPropertiesFromDynamic() {
Map<String, String> properties = new HashMap<>();
properties.put(propertyOneWithDynamic.getName(), propertyOneWithDynamic.get());
properties.put(propertyTwoWithDynamic.getName(), propertyTwoWithDynamic.get());
properties.put(propertyThreeWithDynamic.getName(), propertyThreeWithDynamic.get());
properties.put(propertyFourWithDynamic.getName(), propertyFourWithDynamic.get());
return properties;
}
}

View File

@@ -0,0 +1,3 @@
server.port=8082
baeldung.archaius.properties.one=one FROM:application.properties
baeldung.archaius.properties.two=two FROM:application.properties

View File

@@ -0,0 +1,2 @@
baeldung.archaius.properties.one=one FROM:config.properties
baeldung.archaius.properties.three=three FROM:config.properties

View File

@@ -0,0 +1,2 @@
baeldung.archaius.properties.one=one FROM:other-config.properties
baeldung.archaius.properties.four=four FROM:other-config.properties

View File

@@ -0,0 +1,54 @@
package com.baeldung.spring.cloud.archaius.additionalsources;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ArchaiusAdditionalSourcesLiveTest {
private static final String BASE_URL = "http://localhost:8082";
private static final String DYNAMIC_PROPERTIES_URL = "/properties-from-dynamic";
private static final Map<String, String> EXPECTED_ARCHAIUS_PROPERTIES = createExpectedArchaiusProperties();
private static Map<String, String> createExpectedArchaiusProperties() {
Map<String, String> map = new HashMap<>();
map.put("baeldung.archaius.properties.one", "one FROM:other-config.properties");
map.put("baeldung.archaius.properties.two", "two FROM:application.properties");
map.put("baeldung.archaius.properties.three", "three FROM:config.properties");
map.put("baeldung.archaius.properties.four", "four FROM:other-config.properties");
return map;
}
@Autowired
ConfigurableApplicationContext context;
@Autowired
private TestRestTemplate template;
private <T> Map<T, T> exchangeAsMap(String uri, ParameterizedTypeReference<Map<T, T>> responseType) {
return template.exchange(uri, HttpMethod.GET, null, responseType)
.getBody();
}
@Test
public void givenNonDefaultConfigurationFilesSetup_whenRequestProperties_thenEndpointRetrievesValuesInFiles() {
Map<String, String> initialResponse = this.exchangeAsMap(BASE_URL + DYNAMIC_PROPERTIES_URL, new ParameterizedTypeReference<Map<String, String>>() {
});
assertThat(initialResponse).containsAllEntriesOf(EXPECTED_ARCHAIUS_PROPERTIES);
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>basic-config</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>basic-config</name>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-archaius</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,13 @@
package com.baeldung.spring.cloud.archaius.basic;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BasicArchaiusApplication {
public static void main(String[] args) {
SpringApplication.run(BasicArchaiusApplication.class, args);
}
}

View File

@@ -0,0 +1,70 @@
package com.baeldung.spring.cloud.archaius.basic.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
@RestController
public class ConfigPropertiesController {
@Value("${baeldung.archaius.properties.one:not found!}")
private String propertyOneWithValue;
@Value("${baeldung.archaius.properties.two:not found!}")
private String propertyTwoWithValue;
@Value("${baeldung.archaius.properties.three:not found!}")
private String propertyThreeWithValue;
@Value("${baeldung.archaius.properties.four:not found!}")
private String propertyFourWithValue;
private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.one", "not found!");
private DynamicStringProperty propertyTwoWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.two", "not found!");
private DynamicStringProperty propertyThreeWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.three", "not found!");
private DynamicStringProperty propertyFourWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.four", "not found!");
private DynamicIntProperty intPropertyWithDynamic = DynamicPropertyFactory.getInstance()
.getIntProperty("baeldung.archaius.properties.int", 0);
@GetMapping("/properties-from-value")
public Map<String, String> getPropertiesFromValue() {
Map<String, String> properties = new HashMap<>();
properties.put("baeldung.archaius.properties.one", propertyOneWithValue);
properties.put("baeldung.archaius.properties.two", propertyTwoWithValue);
properties.put("baeldung.archaius.properties.three", propertyThreeWithValue);
properties.put("baeldung.archaius.properties.four", propertyFourWithValue);
return properties;
}
@GetMapping("/properties-from-dynamic")
public Map<String, String> getPropertiesFromDynamic() {
Map<String, String> properties = new HashMap<>();
properties.put(propertyOneWithDynamic.getName(), propertyOneWithDynamic.get());
properties.put(propertyTwoWithDynamic.getName(), propertyTwoWithDynamic.get());
properties.put(propertyThreeWithDynamic.getName(), propertyThreeWithDynamic.get());
properties.put(propertyFourWithDynamic.getName(), propertyFourWithDynamic.get());
return properties;
}
@GetMapping("/int-property")
public Map<String, Integer> getIntPropertyFromDynamic() {
Map<String, Integer> properties = new HashMap<>();
properties.put(intPropertyWithDynamic.getName(), intPropertyWithDynamic.get());
return properties;
}
}

View File

@@ -0,0 +1,3 @@
server.port=8080
baeldung.archaius.properties.one=one FROM:application.properties
baeldung.archaius.properties.two=two FROM:application.properties

View File

@@ -0,0 +1,4 @@
baeldung.archaius.properties.one=one FROM:config.properties
baeldung.archaius.properties.three=three FROM:config.properties
baeldung.archaius.properties.int=1

View File

@@ -0,0 +1,2 @@
baeldung.archaius.properties.one=one FROM:other.properties
baeldung.archaius.properties.four=four FROM:other.properties

View File

@@ -0,0 +1,45 @@
package com.baeldung.spring.cloud.archaius.basic;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
@RunWith(JUnitPlatform.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class ArchaiusBasicConfigurationIntegrationTest {
@Autowired
ConfigurableApplicationContext context;
private DynamicStringProperty testPropertyWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.test.properties.one", "not found!");
@Test
public void givenIntialPropertyValue_whenPropertyChanges_thenArchaiusRetrievesNewValue() {
String initialValue = testPropertyWithDynamic.get();
TestPropertyValues.of("baeldung.archaius.test.properties.one=new-value")
.applyTo(context);
context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("baeldung.archaius.test.properties.one")));
String finalValue = testPropertyWithDynamic.get();
assertThat(initialValue).isEqualTo("test-one");
assertThat(finalValue).isEqualTo("new-value");
}
}

View File

@@ -0,0 +1,74 @@
package com.baeldung.spring.cloud.archaius.basic;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ArchaiusBasicConfigurationLiveTest {
private static final String BASE_URL = "http://localhost:8080";
private static final String DYNAMIC_PROPERTIES_URL = "/properties-from-dynamic";
private static final Map<String, String> EXPECTED_ARCHAIUS_PROPERTIES = createExpectedArchaiusProperties();
private static Map<String, String> createExpectedArchaiusProperties() {
Map<String, String> map = new HashMap<>();
map.put("baeldung.archaius.properties.one", "one FROM:application.properties");
map.put("baeldung.archaius.properties.two", "two FROM:application.properties");
map.put("baeldung.archaius.properties.three", "three FROM:config.properties");
map.put("baeldung.archaius.properties.four", "not found!");
return map;
}
private static final String VALUE_PROPERTIES_URL = "/properties-from-value";
private static final Map<String, String> EXPECTED_VALUE_PROPERTIES = createExpectedValueProperties();
private static Map<String, String> createExpectedValueProperties() {
Map<String, String> map = new HashMap<>();
map.put("baeldung.archaius.properties.one", "one FROM:application.properties");
map.put("baeldung.archaius.properties.two", "two FROM:application.properties");
map.put("baeldung.archaius.properties.three", "not found!");
map.put("baeldung.archaius.properties.four", "not found!");
return map;
}
@Autowired
ConfigurableApplicationContext context;
@Autowired
private TestRestTemplate template;
private <T> Map<T, T> exchangeAsMap(String uri, ParameterizedTypeReference<Map<T, T>> responseType) {
return template.exchange(uri, HttpMethod.GET, null, responseType)
.getBody();
}
@Test
public void givenDefaultConfigurationSetup_whenRequestProperties_thenEndpointRetrievesValuesInFiles() {
Map<String, String> initialResponse = this.exchangeAsMap(BASE_URL + DYNAMIC_PROPERTIES_URL, new ParameterizedTypeReference<Map<String, String>>() {
});
assertThat(initialResponse).containsAllEntriesOf(EXPECTED_ARCHAIUS_PROPERTIES);
}
@Test
public void givenNonDefaultConfigurationFilesSetup_whenRequestSpringVisibleProperties_thenEndpointDoesntRetrieveArchaiusProperties() {
Map<String, String> initialResponse = this.exchangeAsMap(BASE_URL + VALUE_PROPERTIES_URL, new ParameterizedTypeReference<Map<String, String>>() {
});
assertThat(initialResponse).containsAllEntriesOf(EXPECTED_VALUE_PROPERTIES);
}
}

View File

@@ -0,0 +1,3 @@
baeldung.archaius.test.properties.one=test-one
baeldung.archaius.test.properties.two=test-two
baeldung.archaius.test.properties.int=1

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<artifactId>extra-configs</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>extra-configs</name>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-archaius</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<spring-cloud-dependencies.version>2.0.1.RELEASE</spring-cloud-dependencies.version>
</properties>
</project>

View File

@@ -0,0 +1,16 @@
package com.baeldung.spring.cloud.archaius.extraconfigs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ExtraConfigsApplication {
public static void main(String[] args) {
// System properties can be set as command line arguments too
System.setProperty("archaius.configurationSource.additionalUrls", "classpath:other-config-dir/extra.properties");
System.setProperty("archaius.configurationSource.defaultFileName", "other.properties");
SpringApplication.run(ExtraConfigsApplication.class, args);
}
}

View File

@@ -0,0 +1,60 @@
package com.baeldung.spring.cloud.archaius.extraconfigs.controllers;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
@RestController
public class ConfigPropertiesController {
@Value("${baeldung.archaius.properties.one:not found!}")
private String propertyOneWithValue;
@Value("${baeldung.archaius.properties.two:not found!}")
private String propertyTwoWithValue;
@Value("${baeldung.archaius.properties.three:not found!}")
private String propertyThreeWithValue;
@Value("${baeldung.archaius.properties.four:not found!}")
private String propertyFourWithValue;
private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.one", "not found!");
private DynamicStringProperty propertyTwoWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.two", "not found!");
private DynamicStringProperty propertyThreeWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.three", "not found!");
private DynamicStringProperty propertyFourWithDynamic = DynamicPropertyFactory.getInstance()
.getStringProperty("baeldung.archaius.properties.four", "not found!");
@GetMapping("/properties-from-value")
public Map<String, String> getPropertiesFromValue() {
Map<String, String> properties = new HashMap<>();
properties.put("baeldung.archaius.properties.one", propertyOneWithValue);
properties.put("baeldung.archaius.properties.two", propertyTwoWithValue);
properties.put("baeldung.archaius.properties.three", propertyThreeWithValue);
properties.put("baeldung.archaius.properties.four", propertyFourWithValue);
return properties;
}
@GetMapping("/properties-from-dynamic")
public Map<String, String> getPropertiesFromDynamic() {
Map<String, String> properties = new HashMap<>();
properties.put("baeldung.archaius.properties.one", propertyOneWithDynamic.get());
properties.put("baeldung.archaius.properties.two", propertyTwoWithDynamic.get());
properties.put("baeldung.archaius.properties.three", propertyThreeWithDynamic.get());
properties.put("baeldung.archaius.properties.four", propertyFourWithDynamic.get());
return properties;
}
}

View File

@@ -0,0 +1,3 @@
server.port=8081
baeldung.archaius.properties.one=one FROM:application.properties
baeldung.archaius.properties.two=two FROM:application.properties

View File

@@ -0,0 +1,2 @@
baeldung.archaius.properties.one=one FROM:extra.properties
baeldung.archaius.properties.three=three FROM:extra.properties

View File

@@ -0,0 +1,2 @@
baeldung.archaius.properties.one=one FROM:other.properties
baeldung.archaius.properties.four=four FROM:other.properties

View File

@@ -0,0 +1,54 @@
package com.baeldung.spring.cloud.archaius.extraconfigs;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ArchaiusExtraConfigsLiveTest {
private static final String BASE_URL = "http://localhost:8081";
private static final String DYNAMIC_PROPERTIES_URL = "/properties-from-dynamic";
private static final Map<String, String> EXPECTED_ARCHAIUS_PROPERTIES = createExpectedArchaiusProperties();
private static Map<String, String> createExpectedArchaiusProperties() {
Map<String, String> map = new HashMap<>();
map.put("baeldung.archaius.properties.one", "one FROM:application.properties");
map.put("baeldung.archaius.properties.two", "two FROM:application.properties");
map.put("baeldung.archaius.properties.three", "three FROM:extra.properties");
map.put("baeldung.archaius.properties.four", "four FROM:other.properties");
return map;
}
@Autowired
ConfigurableApplicationContext context;
@Autowired
private TestRestTemplate template;
private <T> Map<T, T> exchangeAsMap(String uri, ParameterizedTypeReference<Map<T, T>> responseType) {
return template.exchange(uri, HttpMethod.GET, null, responseType)
.getBody();
}
@Test
public void givenNonDefaultConfigurationFilesSetup_whenRequestProperties_thenEndpointRetrievesValuesInFiles() {
Map<String, String> initialResponse = this.exchangeAsMap(BASE_URL + DYNAMIC_PROPERTIES_URL, new ParameterizedTypeReference<Map<String, String>>() {
});
assertThat(initialResponse).containsAllEntriesOf(EXPECTED_ARCHAIUS_PROPERTIES);
}
}

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-archaius</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>spring-cloud-archaius</name>
<description>Spring Cloud Archaius Pom parent</description>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<modules>
<module>basic-config</module>
<module>additional-sources-simple</module>
<module>extra-configs</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<spring-cloud-dependencies.version>2.0.1.RELEASE</spring-cloud-dependencies.version>
<junit.platform.version>1.2.0</junit.platform.version>
</properties>
</project>

View File

@@ -4,7 +4,6 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-aws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spring Cloud AWS</name>
<description>Spring Cloud AWS Examples</description>
@@ -44,7 +43,6 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
@@ -59,27 +57,8 @@
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<start-class>com.baeldung.spring.cloud.aws.SpringCloudAwsApplication</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR4</spring-cloud.version>
</properties>
</project>

View File

@@ -33,8 +33,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@@ -54,33 +53,8 @@
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IntTest.java</exclude>
<exclude>**/*LongRunningUnitTest.java</exclude>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/JdbcTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<postgresql.version>9.4-1201-jdbc4</postgresql.version>
</properties>
</project>

View File

@@ -0,0 +1,20 @@
--
-- Sample schema for testing vault database secrets
--
create schema fakebank;
use fakebank;
create table account(
id decimal(16,0),
name varchar(30),
branch_id decimal(16,0),
customer_id decimal(16,0),
primary key (id));
--
-- MySQL user that will be used by Vault to create other users on demand
--
create user 'fakebank-admin'@'%' identified by 'Sup&rSecre7!'
grant all privileges on fakebank.* to 'fakebank-admin'@'%' with grant option;
grant create user on *.* to 'fakebank-admin' with grant option;
flush privileges;

View File

@@ -60,7 +60,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-vault-config-databases</artifactId>
<artifactId> </artifactId>
</dependency>
</dependencies>

View File

@@ -0,0 +1,6 @@
path "secret/fakebank" {
capabilities = ["read"]
allowed_parameters = {
"api_key" = []
}
}

View File

@@ -2,4 +2,4 @@
echo Setting environment variables to access local vault..
set VAULT_ADDR=https://localhost:8200
set VAULT_CACERT=%~dp0%/src/test/vault-config/localhost.cert
set VAULT_TLS_SERVER_NAME=localhost
rem set VAULT_TLS_SERVER_NAME=localhost

View File

@@ -1,6 +1,6 @@
#!/bin/bash
echo Setting environment variables to access local vault..
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
SCRIPTPATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
export VAULT_ADDR=https://localhost:8200
export VAULT_CACERT=$SCRIPTPATH/src/test/vault-config/localhost.cert
export VAULT_TLS_SERVER_NAME=localhost