i use springboot to api server..
controller
@RestController
@RequestMapping("/health")
public class HealthController {
private static Logger logger = LoggerFactory.getLogger(HealthController.class);
@GetMapping("")
public boolean health() {
return true;
}
@GetMapping("/message")
public String message() {
return GradeType.PRIMARY_FOURTH.getName();
}
}
WebMvcConfigurer
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
MediaType jsonMediaType = MediaType.valueOf("application/json;charset=UTF-8");
configurer
.mediaType("json", jsonMediaType)
.mediaType("html", MediaType.TEXT_HTML)
.mediaType("zip", MediaType.valueOf("application/zip"))
.mediaType("txt", MediaType.valueOf("text/html;charset=UTF-8"))
.defaultContentType(jsonMediaType)
.ignoreAcceptHeader(true)
.useRegisteredExtensionsOnly(true);
}
}
/health -> 200 OK
/health.json -> 404 ERROR
It’s a minor problem, but I want to solve it.
call url with .json extension, result 200 OK
New contributor
Jedi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.