2016-04-22 21 views
5

tôi đã viết một REST Gọi đó sẽ trở lại tình trạng sức khỏe khi gọiXuân Nghỉ ngơi Dịch vụ Gọi trở về lỗi trên dòng 1 ở cột 1: Tài liệu rỗng

@RestController 
@RequestMapping(value = "/account") 
public class HealthCheckController { 

    protected final Logger log = LoggerFactory.getLogger(this.getClass()); 

    @RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json" }) 
    @ResponseStatus(HttpStatus.OK) 
    @ApiOperation(value = "Returns the health status of the application", notes = "Load balancer user this to confirm the health of the node") 
    public @ResponseBody String getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

     log.info("***" + RequestCorrelation.getId() + "***" + "HealthCheckController - getHealth() Called"); 

     return "{\"health\":{\"SERVICES\":\"OK\"}}"; 
    } 

} 

Khi tôi mở này trong vênh vang hoặc đưa thư nó sẽ trả về phản ứng thích hợp . Nhưng khi tôi nhấn URL này trong trình duyệt chrome, tôi đang thấy

Tại sao vậy? và cách khắc phục điều này?

Trả lời

0

Cố gắng trở lại không phải là một chuỗi nhưng

return new ResponseEntity<>(yourString, HttpStatus.OK); 

và cũng thay đổi này

public @ResponseBody String getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

này

public @ResponseBody ResponseEntity<String> getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception { 

Và nếu nó không hoạt động, cố gắng thêm. xml hoặc .json vào cuối URL của bạn, khi bạn truy cập nó trong trình duyệt.

Các vấn đề liên quan