本文整理了Java中org.springframework.web.bind.annotation.ExceptionHandler.value()
方法的一些代码示例,展示了ExceptionHandler.value()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionHandler.value()
方法的具体详情如下:
包路径:org.springframework.web.bind.annotation.ExceptionHandler
类名称:ExceptionHandler
方法名:value
暂无
代码示例来源:origin: spring-projects/spring-framework
private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
ExceptionHandler ann = AnnotatedElementUtils.findMergedAnnotation(method, ExceptionHandler.class);
Assert.state(ann != null, "No ExceptionHandler annotation");
result.addAll(Arrays.asList(ann.value()));
}
代码示例来源:origin: org.springframework/spring-web
private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
ExceptionHandler ann = AnnotatedElementUtils.findMergedAnnotation(method, ExceptionHandler.class);
Assert.state(ann != null, "No ExceptionHandler annotation");
result.addAll(Arrays.asList(ann.value()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void supportsAllDefaultHandlerExceptionResolverExceptionTypes() throws Exception {
Class<ResponseEntityExceptionHandler> clazz = ResponseEntityExceptionHandler.class;
Method handleExceptionMethod = clazz.getMethod("handleException", Exception.class, WebRequest.class);
ExceptionHandler annotation = handleExceptionMethod.getAnnotation(ExceptionHandler.class);
List<Class<?>> exceptionTypes = Arrays.asList(annotation.value());
for (Method method : DefaultHandlerExceptionResolver.class.getDeclaredMethods()) {
Class<?>[] paramTypes = method.getParameterTypes();
if (method.getName().startsWith("handle") && (paramTypes.length == 4)) {
String name = paramTypes[0].getSimpleName();
assertTrue("@ExceptionHandler is missing " + name, exceptionTypes.contains(paramTypes[0]));
}
}
}
代码示例来源:origin: kongchen/swagger-maven-plugin
protected Map<Class<? extends Throwable>, ResponseStatus> generateExceptionMapping(Set<Class<?>> classes) {
Map<Class<? extends Throwable>, ResponseStatus> result =
new HashMap<Class<? extends Throwable>, ResponseStatus>();
log.debug(String.format("Looking for classes with @ControllerAdvice annotation"));
for (Class clazz: classes) {
ControllerAdvice advice = findAnnotation(clazz, ControllerAdvice.class);
if (advice == null) {
continue;
}
log.debug(String.format("%s is annotated as @ControllerAdvice", clazz.getName()));
for (Method method: clazz.getMethods()) {
ExceptionHandler handler = findAnnotation(method, ExceptionHandler.class);
if (handler == null) {
log.debug(String.format("@ExceptionHandler is missing on %s method, skipping", method));
continue;
}
ResponseStatus responseStatus = findAnnotation(method, ResponseStatus.class);
if (responseStatus == null) {
log.debug(String.format("@ResponseStatus is missing on %s method, skipping", method));
continue;
}
Class[] exceptionClasses = handler.value();
for (Class exceptionClass: exceptionClasses) {
log.debug(String.format("%s will be mapped to %s", exceptionClass, responseStatus));
result.put(exceptionClass, responseStatus);
}
}
}
return result;
}
代码示例来源:origin: apache/servicemix-bundles
protected void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
ExceptionHandler ann = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
Assert.state(ann != null, "No ExceptionHandler annotation");
result.addAll(Arrays.asList(ann.value()));
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
ExceptionHandler ann = AnnotatedElementUtils.findMergedAnnotation(method, ExceptionHandler.class);
Assert.state(ann != null, "No ExceptionHandler annotation");
result.addAll(Arrays.asList(ann.value()));
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Returns all the exception classes handled by the given method.
* <p>The default implementation looks for exceptions in the annotation,
* or - if that annotation element is empty - any exceptions listed in the method parameters if the method
* is annotated with {@code @ExceptionHandler}.
* @param method the method
* @return the handled exceptions
*/
@SuppressWarnings("unchecked")
protected List<Class<? extends Throwable>> getHandledExceptions(Method method) {
List<Class<? extends Throwable>> result = new ArrayList<Class<? extends Throwable>>();
ExceptionHandler exceptionHandler = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
if (exceptionHandler != null) {
if (!ObjectUtils.isEmpty(exceptionHandler.value())) {
result.addAll(Arrays.asList(exceptionHandler.value()));
}
else {
for (Class<?> param : method.getParameterTypes()) {
if (Throwable.class.isAssignableFrom(param)) {
result.add((Class<? extends Throwable>) param);
}
}
}
}
return result;
}
代码示例来源:origin: org.springframework/org.springframework.web.portlet
/**
* Returns all the exception classes handled by the given method.
* <p>Default implementation looks for exceptions in the {@linkplain ExceptionHandler#value() annotation},
* or - if that annotation element is empty - any exceptions listed in the method parameters if the
* method is annotated with {@code @ExceptionHandler}.
* @param method the method
* @return the handled exceptions
*/
@SuppressWarnings("unchecked")
protected List<Class<? extends Throwable>> getHandledExceptions(Method method) {
List<Class<? extends Throwable>> result = new ArrayList<Class<? extends Throwable>>();
ExceptionHandler exceptionHandler = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
if (exceptionHandler != null) {
if (!ObjectUtils.isEmpty(exceptionHandler.value())) {
result.addAll(Arrays.asList(exceptionHandler.value()));
}
else {
for (Class<?> param : method.getParameterTypes()) {
if (Throwable.class.isAssignableFrom(param)) {
result.add((Class<? extends Throwable>) param);
}
}
}
}
return result;
}
代码示例来源:origin: org.springframework/spring-webmvc-portlet
/**
* Returns all the exception classes handled by the given method.
* <p>Default implementation looks for exceptions in the {@linkplain ExceptionHandler#value() annotation},
* or - if that annotation element is empty - any exceptions listed in the method parameters if the
* method is annotated with {@code @ExceptionHandler}.
* @param method the method
* @return the handled exceptions
*/
@SuppressWarnings("unchecked")
protected List<Class<? extends Throwable>> getHandledExceptions(Method method) {
List<Class<? extends Throwable>> result = new ArrayList<Class<? extends Throwable>>();
ExceptionHandler exceptionHandler = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
if (exceptionHandler != null) {
if (!ObjectUtils.isEmpty(exceptionHandler.value())) {
result.addAll(Arrays.asList(exceptionHandler.value()));
}
else {
for (Class<?> param : method.getParameterTypes()) {
if (Throwable.class.isAssignableFrom(param)) {
result.add((Class<? extends Throwable>) param);
}
}
}
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!