I have a gradle project and I am using spring-boot in my backend and for the front-end Angular 2. Every time I do a get-Request after add or delete, the IE does not call the get-method. He takes the array from the cache.
I have already found a solution client side. I have put the headers:
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
in my Request. And then it works.
But I tried to solve this problem server side. I found in the internet, that you can prevent caching if you just add
spring.cache.type=NONE
in your application.properties. But this is not working.
Did I forgot anything else?
Application:
@SpringBootApplication
public class MyApplicationextends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
UIController:
@RequestMapping("/service")
public interface MyUIController {
@RequestMapping(method=RequestMethod.GET, value= "/getBooks", produces="application/json")
public List<Books> getBooks(HttpServletRequest request, HttpServletResponse response);
}
RestController:
@RestController
public class MyRestController implements MyUIController {
public List<DomainEntity> getDomains(HttpServletRequest request, HttpServletResponse response) {
return myUIService.getBookss(request, response);
Service:
@Service
public class MyUIService {
public List<Books> getBooks(HttpServletRequest request, HttpServletResponse response) {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<List<Books>> responseEntity = restTemplate.exchange(
UriComponentsBuilder.fromHttpUrl(url).build().encode().toUri(),
HttpMethod.GET,
requestEntity,
new ParameterizedTypeReference<List<Books>>(){});
return responseEntity.getBody();
}