This small java library is used with spring to use Annotations for HTTP Response Headers.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


  • Latest Release: GitHub version
  • Build Status: Build Status

This small java library is used with spring to use Annotations for HTTP Response Headers.


You can specifiy @HttpResponseHeader and @HttpResponseHeaders for methods and classes. If an annotation is visible on method level it will ignore the class level one. If the class annotation provides the same header key like a method annotation, the method annotation will override the value of the class annotation.


/* One Header */
@HttpResponseHeader(name="X-Key", value="X-Value-Method")
public String handleExtraAnnotatedMethod() {
    return null;

/* Multiple headers */
        @HttpResponseHeader(name="X-Key-One", value="X-Value-One-Method"),
        @HttpResponseHeader(name="X-Key-Two", value="X-Value-Two-Method")
public String handleMultipleExtraAnnotatedMethod() {
    return null;


@HttpResponseHeader(name="X-Key-For-Response-Header", value="X-Value-For-Response-Header-Class")
        @HttpResponseHeader(name="X-Key-For-Response-Headers-One", value="X-Value-For-Response-Headers-One-Class"),
        @HttpResponseHeader(name="X-Key-For-Response-Headers-Two", value="X-Value-For-Response-Headers-Two-Class")
public class FullyAnnotatedTestController  {
    /* ... */

Spring Expression Language

It's also possible, to use SpEL for the name and value property.

To enable parsing for the value property, enable it with valueExpression=true.

For example:

@HttpResponseHeader(name="Cache-Control", value="#{'max-age=' + (60*5)}", valueExpression=true)

will result in:

Cache-Control: max-age=300

If you use that to read properties (like java.version):

@HttpResponseHeader(name="X-Java-Version", value="#{environment.getProperty('java.version')}", valueExpression=true)

will result in:

X-Java-Version: 1.8.0_25


Replace VERSION with GitHub version or 0.3.0-SNAPSHOT.




compile 'net.dracoblue.spring:http-response-headers:VERSION'

Add this to your SpringBootApplication:

HttpResponseHeaderHandlerInterceptor httpResponsHeaderHandlerInterceptor;

public WebMvcConfigurer contentNegotiatorConfigurer()
    return new WebMvcConfigurerAdapter()
       public void addInterceptors(InterceptorRegistry registry)

Other Projects / Interesting Links


This work is copyright by DracoBlue ( and licensed under the terms of MIT License.