Spring MVC @getMapping headers, set value from application properties

769 views Asked by At

I want to set value from application properties for @getMapping headers. I was trying this

@GetMapping(path = "/test/classify/{id}",
        headers = "${partners.api-key}")

But it doesn't work. Is it possible to do that? Thanks in advance.

1

There are 1 answers

1
Armin Ghavidel On

hi I think you should use @Value to get property and HttpServletResponse to set the header like this:

@Value("${partners.api-key}")
private String apiKey;

@GetMapping(path = "/test/classify/{id}")
public Object get(HttpServletResponse response){
    .....
    response.addHeader("api-key", apiKey);
    return object;
}