|
3 | 3 |
|
4 | 4 | This quick start walks through using both the server and the client of Spring Cloud Config Server. |
5 | 5 |
|
6 | | -First, start the server, as follows: |
| 6 | +First create a Spring Boot application with a dependency on `org.springframework.cloud:spring-cloud-config-server`. |
7 | 7 |
|
| 8 | +.pom.xml |
| 9 | +[source,xml] |
| 10 | +---- |
| 11 | +... |
| 12 | + <properties> |
| 13 | + <java.version>21</java.version> |
| 14 | + <spring-cloud.version>2025.1.0</spring-cloud.version> |
| 15 | + </properties> |
| 16 | + <dependencies> |
| 17 | + <dependency> |
| 18 | + <groupId>org.springframework.cloud</groupId> |
| 19 | + <artifactId>spring-cloud-config-server</artifactId> |
| 20 | + </dependency> |
| 21 | +
|
| 22 | + <dependency> |
| 23 | + <groupId>org.springframework.boot</groupId> |
| 24 | + <artifactId>spring-boot-starter-test</artifactId> |
| 25 | + <scope>test</scope> |
| 26 | + </dependency> |
| 27 | + </dependencies> |
| 28 | + <dependencyManagement> |
| 29 | + <dependencies> |
| 30 | + <dependency> |
| 31 | + <groupId>org.springframework.cloud</groupId> |
| 32 | + <artifactId>spring-cloud-dependencies</artifactId> |
| 33 | + <version>${spring-cloud.version}</version> |
| 34 | + <type>pom</type> |
| 35 | + <scope>import</scope> |
| 36 | + </dependency> |
| 37 | + </dependencies> |
| 38 | + </dependencyManagement> |
| 39 | +... |
| 40 | +---- |
| 41 | + |
| 42 | +.build.gradle |
| 43 | +[source,json] |
| 44 | +---- |
| 45 | +... |
| 46 | +ext { |
| 47 | + set('springCloudVersion', "2025.1.0") |
| 48 | +} |
| 49 | +
|
| 50 | +dependencies { |
| 51 | + implementation 'org.springframework.cloud:spring-cloud-config-server' |
| 52 | +} |
| 53 | +
|
| 54 | +dependencyManagement { |
| 55 | + imports { |
| 56 | + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" |
| 57 | + } |
| 58 | +} |
| 59 | +... |
8 | 60 | ---- |
9 | | -$ cd spring-cloud-config-server |
10 | | -$ ../mvnw spring-boot:run |
| 61 | + |
| 62 | +In the main application class add the `@EnableConfigServer` annotation. |
| 63 | + |
| 64 | +.ConfigServerApplication.java |
| 65 | +[source,java] |
11 | 66 | ---- |
| 67 | +@EnableConfigServer |
| 68 | +@SpringBootApplication |
| 69 | +public class ConfigServerApplication { |
| 70 | +
|
| 71 | + public static void main(String[] args) { |
| 72 | + new SpringApplicationBuilder(ConfigServerApplication.class).run(args); |
| 73 | + } |
12 | 74 |
|
13 | | -The server is a Spring Boot application, so you can run it from your IDE if you prefer to do so (the main class is `ConfigServerApplication`). |
| 75 | +} |
| 76 | +---- |
| 77 | + |
| 78 | +Finally in your `application.yaml` file (or `application.properties`) add the following properties. |
| 79 | + |
| 80 | +.application.yaml |
| 81 | +[source,yaml] |
| 82 | +---- |
| 83 | +spring: |
| 84 | + application: |
| 85 | + name: configserver |
| 86 | + cloud: |
| 87 | + config: |
| 88 | + server: |
| 89 | + git: |
| 90 | + uri: https://github.com/spring-cloud-samples/config-repo |
| 91 | + repos: |
| 92 | + - patterns: multi-repo-demo-* |
| 93 | + uri: https://github.com/spring-cloud-samples/config-repo |
| 94 | +server: |
| 95 | + port: 8888 |
| 96 | +---- |
14 | 97 |
|
15 | 98 | Next try out a client, as follows: |
16 | 99 |
|
|
0 commit comments