Skip to content

Commit

Permalink
Add Java config instructions to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
foo4u committed Jul 7, 2016
1 parent 4ef4eb1 commit ccfe110
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,32 @@ compile 'net.rossillo.mvc.cache:spring-mvc-cache-control:1.1.1-RELEASE'

### Configuration

Simply include `net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor` in your Spring MVC `-servlet.xml` file:
Simply include `net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor` in your Spring MVC configuration.

#### XML Web Application Context

```
<mvc:interceptors>
<bean class="net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor" />
</mvc:interceptors>
```

_For XML contexts, this usually defaults to `${appName}-servlet.xml`_

#### Java Web Application Context

```
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter implements WebMvcConfigurer
{
@Override
public void addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(new CacheControlHandlerInterceptor());
}
}
```

### Annotate Your Controllers

Use the `@CacheControl` annotation on either (or both) type level `@Controller`s or method level `@RequestMapping`s. The handler interceptor will read the annotations and generate HTTP/1.1 compliant cache-control headers. For example:
Expand Down

0 comments on commit ccfe110

Please sign in to comment.