• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MethodArgumentNotValidException类的典型用法和代码示例

java 1次浏览

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

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

示例1: jmsHandlerMethodFactoryConfiguration

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
			EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:11,
代码来源:EnableJmsTests.java

示例2: jmsHandlerMethodFactoryConfiguration

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
	ApplicationContext context = new ClassPathXmlApplicationContext(
			"annotation-driven-custom-handler-method-factory.xml", getClass());

	thrown.expect(ListenerExecutionFailedException.class);
	thrown.expectCause(Is.<MethodArgumentNotValidException>isA(MethodArgumentNotValidException.class));
	testJmsHandlerMethodFactoryConfiguration(context);
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:11,
代码来源:AnnotationDrivenNamespaceTests.java

示例3: handleValidationError

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@MessageExceptionHandler
@SendToUser("/queue/errors")
public UIError handleValidationError(MethodArgumentNotValidException exception) {
    logger.error("Invalid input", exception);
    UIError uiError = new UIError(ERROR_CODE_VALIDATION, ERROR_MSG_VALIDATION, ErrorType.VALIDATION);

    BindingResult result = exception.getBindingResult();
    if (result != null) {
        List<ObjectError> errors = result.getAllErrors();
        uiError.addDetails(errors);
    }
    return uiError;
}
 

开发者ID:luxons,
项目名称:seven-wonders,
代码行数:14,
代码来源:ExceptionHandler.java

示例4: resolveArgument

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter param, Message<?> message)
		throws Exception {
	Payload ann = param.getParameterAnnotation(Payload.class);
	if (ann != null && StringUtils.hasText(ann.value())) {
		throw new IllegalStateException(
				"@Payload SpEL expressions not supported by this resolver");
	}

	Object payload = message.getPayload();
	if (isEmptyPayload(payload)) {
		if (ann == null || ann.required()) {
			String paramName = getParameterName(param);
			BindingResult bindingResult = new BeanPropertyBindingResult(payload,
					paramName);
			bindingResult.addError(
					new ObjectError(paramName, "@Payload param is required"));
			throw new MethodArgumentNotValidException(message, param, bindingResult);
		}
		return null;
	}

	Class<?> targetClass = param.getParameterType();
	if (ClassUtils.isAssignable(targetClass, payload.getClass())) {
		validate(message, param, payload);
		return payload;
	}

	payload = this.methodParameterConverter.convert(param, message.getPayload());
	if (payload == null) {
		throw new MessageConversionException(message,
				"No converter found to convert to " + targetClass + ", message="
						+ message);
	}

	validate(message, param, payload);
	return payload;
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:39,
代码来源:PayloadArgumentResolver.java

示例5: validate

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
protected void validate(Message<?> message, MethodParameter parameter,
		Object target) {
	if (this.validator == null) {
		return;
	}
	for (Annotation ann : parameter.getParameterAnnotations()) {
		Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class);
		if (validatedAnn != null
				|| ann.annotationType().getSimpleName().startsWith("Valid")) {
			Object hints = validatedAnn != null ? validatedAnn.value()
					: AnnotationUtils.getValue(ann);
			Object[] validationHints = hints instanceof Object[] ? (Object[]) hints
					: new Object[] { hints };
			BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(
					target, getParameterName(parameter));
			if (!ObjectUtils.isEmpty(validationHints)
					&& this.validator instanceof SmartValidator) {
				((SmartValidator) this.validator).validate(target, bindingResult,
						validationHints);
			}
			else {
				this.validator.validate(target, bindingResult);
			}
			if (bindingResult.hasErrors()) {
				throw new MethodArgumentNotValidException(message, parameter,
						bindingResult);
			}
			break;
		}
	}
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:32,
代码来源:PayloadArgumentResolver.java

示例6: resolveNonAnnotatedParameter

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test
public void resolveNonAnnotatedParameter() throws Exception {
	PublishMessage notEmptyMessage = new PublishMessage("pub", "ABC");
	assertEquals("ABC",
			this.resolver.resolveArgument(this.paramNotAnnotated, notEmptyMessage));

	Message<?> emptyStringMessage = MessageBuilder.withPayload("").build();
	this.thrown.expect(MethodArgumentNotValidException.class);
	this.resolver.resolveArgument(this.paramValidated, emptyStringMessage);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:11,
代码来源:PayloadArgumentResolverTest.java

示例7: resolveNonAnnotatedParameterFailValidation

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test
public void resolveNonAnnotatedParameterFailValidation() throws Exception {
	// See testValidator()
	PublishMessage message = new PublishMessage("pub", "invalidValue");

	this.thrown.expect(MethodArgumentNotValidException.class);
	this.thrown.expectMessage("invalid value");
	assertEquals("invalidValue",
			this.resolver.resolveArgument(this.paramValidatedNotAnnotated, message));
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:11,
代码来源:PayloadArgumentResolverTest.java

示例8: getEntity

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Override
protected Object getEntity(MethodArgumentNotValidException exception) {
    ValidationResult result = new ValidationResult();
    for (FieldError err : exception.getBindingResult().getFieldErrors()) {
        result.addValidationError(err.getField(), err.getDefaultMessage());
    }
    return result;
}
 

开发者ID:hortonworks,
项目名称:cloudbreak,
代码行数:9,
代码来源:MethodArgumentNotValidExceptionMapper.java

示例9: bindEmptyPayloadError

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
private void bindEmptyPayloadError(MethodParameter parameter, Message<?> message, Object payload) {
    String paramName = getParameterName(parameter);
    BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName);
    bindingResult.addError(new ObjectError(paramName, "@Payload param is required"));
    throw new MethodArgumentNotValidException(message, parameter, bindingResult);
}
 

开发者ID:kinglcc,
项目名称:spring-boot-jms,
代码行数:7,
代码来源:Jackson2PayloadArgumentResolver.java

示例10: handleValidationException

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@MessageExceptionHandler(MethodArgumentNotValidException.class)
public void handleValidationException() {
	this.method = "handleValidationException";
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:5,
代码来源:SimpAnnotationMethodMessageHandlerTests.java

示例11: resolveRequiredEmpty

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test(expected = MethodArgumentNotValidException.class)
public void resolveRequiredEmpty() throws Exception {
	PublishMessage message = new PublishMessage("pub", "");
	this.resolver.resolveArgument(this.paramAnnotated, message);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:6,
代码来源:PayloadArgumentResolverTest.java

示例12: resolveRequiredEmptyAnnotated

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test(expected = MethodArgumentNotValidException.class)
public void resolveRequiredEmptyAnnotated() throws Exception {
	PublishMessage message = new PublishMessage("pub", "");
	this.resolver.resolveArgument(this.paramAnnotatedRequired, message);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:6,
代码来源:PayloadArgumentResolverTest.java

示例13: resolveRequiredEmptyNonAnnotatedParameter

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test(expected = MethodArgumentNotValidException.class)
public void resolveRequiredEmptyNonAnnotatedParameter() throws Exception {
	PublishMessage message = new PublishMessage("pub", "");
	this.resolver.resolveArgument(this.paramNotAnnotated, message);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:6,
代码来源:PayloadArgumentResolverTest.java

示例14: resolveFailValidation

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test(expected = MethodArgumentNotValidException.class)
public void resolveFailValidation() throws Exception {
	// See testValidator()
	PublishMessage message = new PublishMessage("pub", "invalidValue");
	this.resolver.resolveArgument(this.paramValidated, message);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:7,
代码来源:PayloadArgumentResolverTest.java

示例15: resolveFailValidationNoConversionNecessary

点赞 2

import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException; //导入依赖的package包/类
@Test(expected = MethodArgumentNotValidException.class)
public void resolveFailValidationNoConversionNecessary() throws Exception {
	PublishMessage message = new PublishMessage("pub", "invalidValue");
	this.resolver.resolveArgument(this.paramValidated, message);
}
 

开发者ID:ralscha,
项目名称:wampspring,
代码行数:6,
代码来源:PayloadArgumentResolverTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)