springboot 404 처리

2032 단어
자세히 보기
@Controller
@RequestMapping("/error")
public class MyErrorController{
	private static final Logger	log	= Logger.getLogger( WebExceptionHandler.class );
	private static final String ERROR_PATH="/";
	@RequestMapping(value =ERROR_PATH )
	public String handleError(ServletRequest request, ServletResponse rsp) {
		log.info(" ~");
		return "error/error";
	}
	@RequestMapping(value ="/403" )
	public String error403(ServletRequest request, ServletResponse rsp) {
		log.info("403 ~");
		return "error/403";
	}
	@RequestMapping(value ="/404" )
	public String error404(ServletRequest request, ServletResponse rsp) {
		log.info("404 ~");
		return "error/404";
	}
	@RequestMapping(value ="/500" )
	public String error500(ServletRequest request, ServletResponse rsp) {
		log.info("500 ~");
		return "error/500";
	}
	@RequestMapping(value ="/locked" )
	public String errorlocked(ServletRequest request, ServletResponse rsp) {
		log.info("locked~");
		return "error/locked";
	}
	@RequestMapping(value ="/noauth" )
	public String errornoauth(ServletRequest request, ServletResponse rsp) {
		log.info("noauth~");
		return "error/noauth";
	}
}

 
@Configuration
public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter implements EmbeddedServletContainerCustomizer {
	private static final Log	log	= LogFactory.getLog( MyWebMvcConfigurer.class );

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
    	log.info( "== ==" );
    	container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"));
    }

}

 

좋은 웹페이지 즐겨찾기