BAEL-614 endpoint that has default cache-control headers

This commit is contained in:
Tomasz Lelek 2017-01-26 20:16:31 +01:00 committed by Andrew Morgan
parent 3fa1b93f87
commit 4bac6e0571
2 changed files with 6 additions and 21 deletions

View File

@ -32,4 +32,10 @@ public class ResourceEndpoint {
.cacheControl(CacheControl.noCache())
.body(new TimestampDto(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli()));
}
@RequestMapping(value = "/private/users/{name}", method = RequestMethod.GET)
public ResponseEntity<UserDto> getUserNotCached(@PathVariable("name") String name) {
return ResponseEntity.ok()
.body(new UserDto(name));
}
}

View File

@ -1,21 +0,0 @@
package com.baeldung.cachecontrol.config;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.concurrent.TimeUnit;
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.setCacheControl(CacheControl.maxAge(24, TimeUnit.HOURS));
}
}