当前位置: 首页>>代码示例>>Java>>正文


Java NoHandlerFoundException类代码示例

本文整理汇总了Java中org.springframework.web.servlet.NoHandlerFoundException的典型用法代码示例。如果您正苦于以下问题:Java NoHandlerFoundException类的具体用法?Java NoHandlerFoundException怎么用?Java NoHandlerFoundException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoHandlerFoundException类属于org.springframework.web.servlet包,在下文中一共展示了NoHandlerFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleNoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
public @ResponseBody ErrorWrapper handleNoHandlerFoundException(HttpServletRequest request, HttpServletResponse response, Exception ex){
    ErrorWrapper errorWrapper = (ErrorWrapper) context.getBean(ErrorWrapper.class.getName());
    Locale locale = null;
    BroadleafRequestContext requestContext = BroadleafRequestContext.getBroadleafRequestContext();
    if (requestContext != null) {
        locale = requestContext.getJavaLocale();
    }

    LOG.error("An error occured invoking a REST service", ex);
    if (locale == null) {
        locale = Locale.getDefault();
    }
    errorWrapper.setHttpStatusCode(HttpStatus.SC_NOT_FOUND);
    response.setStatus(resolveResponseStatusCode(ex, errorWrapper));
    ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context.getBean(ErrorMessageWrapper.class.getName());
    errorMessageWrapper.setMessageKey(resolveClientMessageKey(BroadleafWebServicesException.NOT_FOUND));
    errorMessageWrapper.setMessage(messageSource.getMessage(BroadleafWebServicesException.NOT_FOUND, null,
            BroadleafWebServicesException.NOT_FOUND, locale));
    errorWrapper.getMessages().add(errorMessageWrapper);

    return errorWrapper;
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:24,代码来源:BroadleafSpringRestExceptionMapper.java

示例2: handleUnmapped

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handleUnmapped(HttpServletRequest req) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("page", new Page("mzTabValidator", versionNumber, gaId));
    mav.addObject("error", "Resource not found!");
    mav.addObject("url", req.getRequestURL());
    mav.addObject("timestamp", new Date().toString());
    mav.addObject("status", 404);
    mav.setViewName("error");
    return mav;
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:13,代码来源:ValidationController.java

示例3: requestHandlingNoHandlerFound

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Map<String,String> requestHandlingNoHandlerFound() {
    Map message = new HashMap();
    message.put("error","router is not exists");
    return message;
}
 
开发者ID:Nbsaw,项目名称:miaohu,代码行数:8,代码来源:GlobalExceptionAdvice.java

示例4: configureHandlerExceptionResolvers

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    exceptionResolvers.add(new HandlerExceptionResolver() {
        public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
            Result result = new Result();
            logger.warn(e.getMessage());
            if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
                result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
            } else if (e instanceof IllegalArgumentException) {  //参数检查异常
                result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
            }else if (e instanceof NoHandlerFoundException) {
                result.setCode(ResultCode.NOT_FOUND).setMessage("接口 [" + request.getRequestURI() + "] 不存在");
            } else if (e instanceof ServletException) {
                result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
            } else  if (e instanceof AccessDeniedException){
                result.setCode(ResultCode.PERMIT).setMessage(e.getMessage());
            } else {
                result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage("接口 [" + request.getRequestURI() + "] 内部错误,请联系管理员");
                String message;
                if (handler instanceof HandlerMethod) {
                    HandlerMethod handlerMethod = (HandlerMethod) handler;
                    message = String.format("接口 [%s] 出现异常,方法:%s.%s,异常摘要:%s",
                            request.getRequestURI(),
                            handlerMethod.getBean().getClass().getName(),
                            handlerMethod.getMethod().getName(),
                            e.getMessage());
                } else {
                    message = e.getMessage();
                }
                logger.error(message, e);
            }
            responseResult(response, result);
            return new ModelAndView();
        }

    });
}
 
开发者ID:pandboy,项目名称:pingguopai,代码行数:38,代码来源:WebMvcConfigurer.java

示例5: configureHandlerExceptionResolvers

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    exceptionResolvers.add(new HandlerExceptionResolver() {
        public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
            Result result = new Result();
            if (handler instanceof HandlerMethod) {
                HandlerMethod handlerMethod = (HandlerMethod) handler;

                if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
                    result.setCode(ResultCode.FAIL).setMessage(e.getMessage());
                    logger.info(e.getMessage());
                } else {
                    result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage("接口 [" + request.getRequestURI() + "] 内部错误,请联系管理员");
                    String message = String.format("接口 [%s] 出现异常,方法:%s.%s,异常摘要:%s",
                            request.getRequestURI(),
                            handlerMethod.getBean().getClass().getName(),
                            handlerMethod.getMethod().getName(),
                            e.getMessage());
                    logger.error(message, e);
                }
            } else {
                if (e instanceof NoHandlerFoundException) {
                    result.setCode(ResultCode.NOT_FOUND).setMessage("接口 [" + request.getRequestURI() + "] 不存在");
                } else {
                    result.setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage(e.getMessage());
                    logger.error(e.getMessage(), e);
                }
            }
            responseResult(response, result);
            return new ModelAndView();
        }

    });
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:35,代码来源:WebMvcConfig.java

示例6: handleNoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleNoHandlerFoundException(final NoHandlerFoundException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final String error = "No handler found for " + ex.getHttpMethod() + " " + ex.getRequestURL();

    final ApiError apiError = new ApiError(HttpStatus.NOT_FOUND, ex.getLocalizedMessage(), error);
    return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
 
开发者ID:junneyang,项目名称:xxproject,代码行数:10,代码来源:CustomRestExceptionHandler.java

示例7: handleError404

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
/**
 * Exception Controller.
 * Catches various exceptions thrown throughout the application runtime.
 *
 * @author Ant Kaynak - Github/Exercon
 */

@ExceptionHandler(NoHandlerFoundException.class)
public String handleError404(Exception e , RedirectAttributes attr)   {
        attr.addFlashAttribute("error","Requested page does not exist!");
        return "redirect:/error";
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:13,代码来源:ExceptionController.java

示例8: handleError404

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
/**
 * Exception Controller.
 * Catches various exceptions thrown throughout the application runtime.
 *
 * @author Ant Kaynak - Github/Exercon
 */

@ExceptionHandler(NoHandlerFoundException.class)
public String handleError404(Exception e , RedirectAttributes attr)   {
    e.printStackTrace();
        attr.addFlashAttribute("error","Requested page does not exist!");
        return "redirect:/oups";
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:14,代码来源:ExceptionController.java

示例9: handleNoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ResponseStatus(code = HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public ErrorDto handleNoHandlerFoundException(NoHandlerFoundException ex) {
    return ErrorDto.builder()
            .errorCode(ErrorCodes.NOT_FOUND)
            .message(ex.getLocalizedMessage())
            .build();
}
 
开发者ID:rozidan,项目名称:project-template,代码行数:9,代码来源:GlobalErrorHandlers.java

示例10: handleNoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleNoHandlerFoundException(final NoHandlerFoundException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
	logger.info(ex.getClass().getName());
	//
	final String error = "No handler found for " + ex.getHttpMethod() + " " + ex.getRequestURL();

	final AitException AitException = new AitException(HttpStatus.NOT_FOUND, ex.getLocalizedMessage(), error);
	return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:10,代码来源:AitRestExceptionHandler.java

示例11: defaultNotFoundHandler

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler(value = NoHandlerFoundException.class)
public ModelAndView defaultNotFoundHandler(HttpServletRequest req, Exception e) throws Exception {
	e.printStackTrace();
	ModelAndView mav = new ModelAndView();
	mav.addObject("exception", e);
	mav.addObject("url", req.getRequestURL());
	mav.setViewName("/404");
	return mav;
}
 
开发者ID:mouxiao,项目名称:shootmimi,代码行数:10,代码来源:GlobalExceptionHandler.java

示例12: handleNoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void handleNoHandlerFoundException() throws Exception {
	ServletServerHttpRequest req = new ServletServerHttpRequest(
			new MockHttpServletRequest("GET","/resource"));
	NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(),
			req.getServletRequest().getRequestURI(),req.getHeaders());
	ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
	assertNotNull("No ModelAndView returned", mav);
	assertTrue("No Empty ModelAndView returned", mav.isEmpty());
	assertEquals("Invalid status code", 404, response.getStatus());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:DefaultHandlerExceptionResolverTests.java

示例13: noHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void noHandlerFoundException() {
	ServletServerHttpRequest req = new ServletServerHttpRequest(
			new MockHttpServletRequest("GET","/resource"));
	Exception ex = new NoHandlerFoundException(req.getMethod().toString(),
			req.getServletRequest().getRequestURI(),req.getHeaders());
	testException(ex);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ResponseEntityExceptionHandlerTests.java

示例14: hmsException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@ExceptionHandler( NoHandlerFoundException.class )
@ResponseStatus( value = HttpStatus.BAD_REQUEST )
@ResponseBody
public BaseResponse hmsException( HttpServletRequest req, NoHandlerFoundException exception )
{

    return new BaseResponse( HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(),
                             exception.getMessage() );
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:10,代码来源:HMSRestExceptionHandler.java

示例15: shouldHandleException_should_return_not_found_error_when_passed_NoHandlerFoundException

import org.springframework.web.servlet.NoHandlerFoundException; //导入依赖的package包/类
@Test
public void shouldHandleException_should_return_not_found_error_when_passed_NoHandlerFoundException() {
    // given
    NoHandlerFoundException ex = new NoHandlerFoundException("GET", "/some/url", mock(HttpHeaders.class));

    // when
    ApiExceptionHandlerListenerResult result = listener.shouldHandleException(ex);

    // then
    validateResponse(result, true, Collections.singletonList(testProjectApiErrors.getNotFoundApiError()));
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:12,代码来源:OneOffSpringFrameworkExceptionHandlerListenerTest.java


注:本文中的org.springframework.web.servlet.NoHandlerFoundException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。