How to config default return type Spring Boot

101 Views Asked by At

is there any way to make default content type?

i use this

@Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.APPLICATION_JSON);
    }

and it works good for methods without produces= ....

this method do not work with this config

@GetMapping(value = "/test/{testId}",
            produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    ResponseEntity<Resource> getTestAttachment @PathVariable Integer testId);

when i call this method i got 406 Http error

1

There are 1 best solutions below

0
java developer 111 On

finally found this way

 @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.ALL);
    }