當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeMismatchException.getMessage方法代碼示例

本文整理匯總了Java中org.springframework.beans.TypeMismatchException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeMismatchException.getMessage方法的具體用法?Java TypeMismatchException.getMessage怎麽用?Java TypeMismatchException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.TypeMismatchException的用法示例。


在下文中一共展示了TypeMismatchException.getMessage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolvePreparedArguments

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, argIndex, paramType,
					"Could not convert " + methodType + " argument value of type [" +
					ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:42,代碼來源:ConstructorResolver.java

示例2: resolvePreparedArguments

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
					"Could not convert argument value of type [" + ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:40,代碼來源:ConstructorResolver.java

示例3: processTypeException

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
/**
* Catches the controller path errors of the Rest API.
*
* Example: If a controller declares an integer in the path, but frontend sends anything but an integer.
*/
@ExceptionHandler(TypeMismatchException.class)
public ResponseEntity<ErrorMessage> processTypeException(TypeMismatchException e) {
    log.error("Exception happened", e);

    HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY;
    ErrorMessage msg = new ErrorMessage(
            status.value(),
            status.getReasonPhrase(),
            e.getMessage()
    );
    return new ResponseEntity<>(msg, status);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:BikeMan,代碼行數:18,代碼來源:GeneralExceptionHandler.java

示例4: processTypeException

import org.springframework.beans.TypeMismatchException; //導入方法依賴的package包/類
/**
 * Catches the controller path errors of the Rest API.
 *
 * Example: If a controller declares an integer in the path, but frontend sends anything but an integer.
 */
@ExceptionHandler(TypeMismatchException.class)
public ResponseEntity<AppExceptionMessage> processTypeException(TypeMismatchException e) {
    log.error("Exception happened", e);

    HttpStatus status = HttpStatus.BAD_REQUEST;
    AppExceptionMessage msg = new AppExceptionMessage(
            status.value(),
            status.getReasonPhrase(),
            e.getMessage()
    );
    return new ResponseEntity<>(msg, status);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:BikeMan,代碼行數:18,代碼來源:AppExceptionHandler.java


注:本文中的org.springframework.beans.TypeMismatchException.getMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。