阅读背景:

Spring Cloud zuul自定义异常信息

来源:互联网 

只需要加上一个controller,代码如下:

 

package com.wdlx.filter;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.AbstractErrorController;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/error")
public class GlobalErrorController extends AbstractErrorController {
	@Autowired
	public GlobalErrorController(ErrorAttributes errorAttributes) {
		super(errorAttributes);
	}

	@Override
	public String getErrorPath() {
		return "/error";
	}

	@RequestMapping(produces = MediaType.ALL_VALUE)
	public ResponseEntity error(HttpServletRequest request) {
		HttpStatus status = getStatus(request);
		if (status.is5xxServerError()) {
			// log maybe
		}
		return new ResponseEntity(status);
	}
}
package com.w



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: