1

I have a problem with connecting to application.yml files in my git repository, from a spring-boot application, through a config server. I have followed all the instructions in this tutorial.

https://spring.io/guides/gs/centralized-configuration

** Since I'm new here they don't let me put more than 2 links so I'm writing links like (http:) and the rest.Sorry about that.

when I tried to access through (http:)//localhost:8888/a-bootiful-client/default I can see the message value changes when I make a change in git.

But when I tried to access through (http:)//localhost:8080/message I just see the default value as "Hello default" and it does't change the value to the value in git

Here is my config server build.gradle:

buildscript {
    ext {
        springBootVersion = '1.3.8.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
    baseName = 'config-test-app-server'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.cloud:spring-cloud-config-server')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR7"
    }
}

This is my config server Application class which have the main method

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@EnableConfigServer
@SpringBootApplication
public class ConfigTestAppServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigTestAppServerApplication.class, args);
    }
}

This is my config server application.yml file

server:
 port: 8888

spring:  
 application:
  name: config-service

 cloud:
  config:
   server:
    git:
     uri: https://github.com/kaushiwicky2/config-server-test/tree/master

This is my springboot application's build.gradle file

buildscript {
    ext {
        springBootVersion = '1.3.8.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath('io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE')
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
    baseName = 'config-test-app'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.cloud:spring-cloud-starter-config')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-actuator')

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR7"
    }
}

This is my springboot application's class which contains the main method

package com.example;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RefreshScope
@RestController
class ConfigController {

        @Value("${message: Hello default}")
        private String message;

        @RequestMapping("/message")
        String getMessage() {
            return this.message;
        }
    }

@SpringBootApplication
public class ConfigTestAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigTestAppApplication.class, args);
    }
}

This is my springboot application's boostrap.yml

spring:
 application:
  name: a-bootiful-client

spring:
 cloud:
  config:
   uri: http://localhost:8888

This is my url for git https://github.com/kaushiwicky2/config-server-test/tree/master

My property file for springboot application I'm trying to access in git repository is ' a-bootiful-client.yml '

I'm very new to this cloud config thing and I really need to make this work.If you can tell me where I got wrong and how to fix it.It'll be a great help.

Thanks in advance.

0 Answers0