Home > Net >  @RefreshScope Annotation return an empty data
@RefreshScope Annotation return an empty data

Time:07-18

I Was following this tutorial on YouTube I have been able to successfully run the config server where I host two properties files here File hosted. and on the client side when I tried to consume the value I get an empty response here is the dummy controller I have created.

   import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
@RefreshScope
public class TestController {

    @Value("${test.name}")
    private String product;

    @GetMapping
    public String test() {
        return product;
    }
}

but when I send a get request to route /api/test, I get a response of 200OK with no actual test value. name, What am I doing wrong?.

CodePudding user response:

The tutorial in youtube uses the default naming convetion but you probably have changed it and now spring cloud config server does not know which property file expects your service to have.

In cloud config server the file is saved as product.properties.

For this reason if your client service has some other name, this will not work. To correct it go to the client application and in bootstrap.yaml add the property spring.application.name: product.

  • Related