From 45746fab295828d14754a0b3df82eaa297ad388c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20P=C3=B6ttker?= Date: Tue, 10 Aug 2021 00:31:45 +0200 Subject: [PATCH] Replaces deprecated interfaces Replaces the deprecated - type InstantiationAwareBeanPostProcessorAdapter - type GenericTypeResolver - method StringUtils::isEmpty - field BigDecimal::ROUND_HALF_UP --- .../SpringAutowiredAnnotationBeanPostProcessor.java | 12 +++++------- .../batch/item/support/ScriptItemProcessor.java | 4 ++-- .../order/internal/validator/OrderValidator.java | 7 ++++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/SpringAutowiredAnnotationBeanPostProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/SpringAutowiredAnnotationBeanPostProcessor.java index 56a7f6eaf2..8411fb1f0a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/SpringAutowiredAnnotationBeanPostProcessor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/support/SpringAutowiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,12 +46,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter; import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.BridgeMethodResolver; -import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; @@ -73,8 +72,8 @@ *
  • findAutowiredAnnotation(AccessibleObject ao)
  • * */ -class SpringAutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter - implements MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware { +class SpringAutowiredAnnotationBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor, + MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware { protected final Log logger = LogFactory.getLog(getClass()); @@ -539,8 +538,7 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T Set autowiredBeanNames = new LinkedHashSet<>(paramTypes.length); TypeConverter typeConverter = beanFactory.getTypeConverter(); for (int i = 0; i < arguments.length; i++) { - MethodParameter methodParam = new MethodParameter(method, i); - GenericTypeResolver.resolveParameterType(methodParam, bean.getClass()); + MethodParameter methodParam = new MethodParameter(method, i).withContainingClass(bean.getClass()); descriptors[i] = new DependencyDescriptor(methodParam, this.required); arguments[i] = beanFactory.resolveDependency( descriptors[i], beanName, autowiredBeanNames, typeConverter); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java index 7fad4db9c8..cee4e38bf4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ScriptItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,7 +134,7 @@ public void afterPropertiesSet() throws Exception { "Either a script source or script file must be provided, not both"); if (scriptSource != null && scriptEvaluator instanceof StandardScriptEvaluator) { - Assert.isTrue(!StringUtils.isEmpty(language), + Assert.isTrue(StringUtils.hasLength(language), "Language must be provided when using the default ScriptEvaluator and raw source code"); ((StandardScriptEvaluator) scriptEvaluator).setLanguage(language); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidator.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidator.java index d24452a66d..c7801cc787 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidator.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/validator/OrderValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.batch.sample.domain.order.internal.validator; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -140,7 +141,7 @@ protected void validateLineItems(List lineItems, Errors errors) { //discount coefficient = (100.00 - discountPerc) / 100.00 BigDecimal coef = BD_100.subtract(lineItem.getDiscountPerc()) - .divide(BD_100, 4, BigDecimal.ROUND_HALF_UP); + .divide(BD_100, 4, RoundingMode.HALF_UP); //discountedPrice = (price * coefficient) - discountAmount //at least one of discountPerc and discountAmount is 0 - this is validated by ValidateDiscountsFunction @@ -154,7 +155,7 @@ protected void validateLineItems(List lineItems, Errors errors) { //total price = singleItemPrice * quantity BigDecimal quantity = new BigDecimal(lineItem.getQuantity()); BigDecimal totalPrice = singleItemPrice.multiply(quantity) - .setScale(2, BigDecimal.ROUND_HALF_UP); + .setScale(2, RoundingMode.HALF_UP); //calculatedPrice should equal to item.totalPrice if (totalPrice.compareTo(lineItem.getTotalPrice()) != 0) {