Property value could not be read when using @RefreshScope in spring controller

1000 Views Asked by At

I am writing 2 applications using cloud config, one the server and another is the client. The server is running on 8888 and holding the configuration stored in GIT repository. It has the property:

spring.cloud.config.server.git.uri=${HOME}/Desktop/config-repo

The client is using the above configuration where it has one property as: message. Client is a restful webservice which has a controller as:

@RestController
class Controller{

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

    @Value ("${course}")
    private String course;

    @RequestMapping("/showMessage")
    private String showMessage(){
        return message;
    }

    @RequestMapping("/showCourse")
    private String showCourse(){
        return course;
    }
}

When accessing http://localhost:8080/showCourse it is perfectly working and showing the message in the web page which is configured in the message.properties.


Issue when using @RefreshScope

Now when I am using @RefreshScope with the controller, I am not at all getting any output where the webpage is blank. When debugging, the issue is with

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

@RequestMapping("/showMessage")
private String showMessage(){
    return message;
}

in the controller where the message is null.

This happens when using the annotation - RefreshScope.

I have added the code/project at GIT: https://github.com/santoshkar/SpringBootCentralConfigUsingGit.git

Kindly help.

Thanks, Santosh

0

There are 0 best solutions below