Iroch
Iroch

Reputation: 19

Passing value to placeholder in spring annotation

I have generated a client interface from api specs

@FeignClient(
    name = "${testController.name:testController}",
    url = "${testController.url:https://api.dev.foo}",
    configuration = {ClientConfiguration.class}
)
public interface TetsControllerApiClient extends TestControllerApi {
}

How can I override the name, or url properties on it? Will appreciate an help. Thanks.

Upvotes: 0

Views: 1060

Answers (2)

Nikolas
Nikolas

Reputation: 44466

This is loaded from the properties file (either application.yml or application.properties).

The notation ${testController.name:testController} is a Spring expression language and says the following:

  • Load testController.name and read its value from the properties.
  • If it is not found, use testController as a default value instead.

The application.properties file shall look like:

testController.name=myTestController

To override the value you can use Spring profiles. File application-local-dev.properties and starting the application with the local-dev profile.

Upvotes: 3

matrixguy
matrixguy

Reputation: 306

You can override them in your application.properties file in your project

testController.name = "myController"
testController.url = "some url"

Upvotes: 1

Related Questions