diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 17e5563159..b071f7c46b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -159,6 +159,9 @@ import org.springframework.util.StringUtils; public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanRegistrationAotProcessor, PriorityOrdered, BeanFactoryAware { + private static final Constructor[] EMPTY_CONSTRUCTOR_ARRAY = new Constructor[0]; + + protected final Log logger = LogFactory.getLog(getClass()); private final Set> autowiredAnnotationTypes = new LinkedHashSet<>(4); @@ -193,9 +196,10 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA this.autowiredAnnotationTypes.add(Autowired.class); this.autowiredAnnotationTypes.add(Value.class); + ClassLoader classLoader = AutowiredAnnotationBeanPostProcessor.class.getClassLoader(); try { this.autowiredAnnotationTypes.add((Class) - ClassUtils.forName("jakarta.inject.Inject", AutowiredAnnotationBeanPostProcessor.class.getClassLoader())); + ClassUtils.forName("jakarta.inject.Inject", classLoader)); logger.trace("'jakarta.inject.Inject' annotation found and supported for autowiring"); } catch (ClassNotFoundException ex) { @@ -204,7 +208,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA try { this.autowiredAnnotationTypes.add((Class) - ClassUtils.forName("javax.inject.Inject", AutowiredAnnotationBeanPostProcessor.class.getClassLoader())); + ClassUtils.forName("javax.inject.Inject", classLoader)); logger.trace("'javax.inject.Inject' annotation found and supported for autowiring"); } catch (ClassNotFoundException ex) { @@ -285,9 +289,16 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA @Override public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + // Register externally managed config members on bean definition. findInjectionMetadata(beanName, beanType, beanDefinition); } + @Override + public void resetBeanDefinition(String beanName) { + this.lookupMethodsChecked.remove(beanName); + this.injectionMetadataCache.remove(beanName); + } + @Override @Nullable public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { @@ -323,12 +334,6 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA return metadata; } - @Override - public void resetBeanDefinition(String beanName) { - this.lookupMethodsChecked.remove(beanName); - this.injectionMetadataCache.remove(beanName); - } - @Override public Class determineBeanType(Class beanClass, String beanName) throws BeanCreationException { checkLookupMethods(beanClass, beanName); @@ -428,7 +433,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA "default constructor to fall back to: " + candidates.get(0)); } } - candidateConstructors = candidates.toArray(new Constructor[0]); + candidateConstructors = candidates.toArray(EMPTY_CONSTRUCTOR_ARRAY); } else if (rawCandidates.length == 1 && rawCandidates[0].getParameterCount() > 0) { candidateConstructors = new Constructor[] {rawCandidates[0]}; @@ -441,7 +446,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA candidateConstructors = new Constructor[] {primaryConstructor}; } else { - candidateConstructors = new Constructor[0]; + candidateConstructors = EMPTY_CONSTRUCTOR_ARRAY; } this.candidateConstructorsCache.put(beanClass, candidateConstructors); } @@ -1011,7 +1016,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA hints.reflection().registerField(field); CodeBlock resolver = CodeBlock.of("$T.$L($S)", AutowiredFieldValueResolver.class, - (!required) ? "forField" : "forRequiredField", field.getName()); + (!required ? "forField" : "forRequiredField"), field.getName()); AccessControl accessControl = AccessControl.forMember(field); if (!accessControl.isAccessibleFrom(targetClassName)) { return CodeBlock.of("$L.resolveAndSet($L, $L)", resolver, @@ -1026,7 +1031,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA CodeBlock.Builder code = CodeBlock.builder(); code.add("$T.$L", AutowiredMethodArgumentsResolver.class, - (!required) ? "forMethod" : "forRequiredMethod"); + (!required ? "forMethod" : "forRequiredMethod")); code.add("($S", method.getName()); if (method.getParameterCount() > 0) { code.add(", $L", generateParameterTypesCode(method.getParameterTypes())); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java index 9efbc3b9b8..0fc15c5a35 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java @@ -71,7 +71,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { synchronized (bd.constructorArgumentLock) { constructorToUse = (Constructor) bd.resolvedConstructorOrFactoryMethod; if (constructorToUse == null) { - final Class clazz = bd.getBeanClass(); + Class clazz = bd.getBeanClass(); if (clazz.isInterface()) { throw new BeanInstantiationException(clazz, "Specified class is an interface"); } @@ -104,7 +104,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { @Override public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, - final Constructor ctor, Object... args) { + Constructor ctor, Object... args) { if (!bd.hasMethodOverrides()) { return BeanUtils.instantiateClass(ctor, args); @@ -128,7 +128,7 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { @Override public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, - @Nullable Object factoryBean, final Method factoryMethod, Object... args) { + @Nullable Object factoryBean, Method factoryMethod, Object... args) { try { ReflectionUtils.makeAccessible(factoryMethod); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index d99e31d87c..3dc8360f6e 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -547,10 +547,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } /** - * Collect the {@link CachePutRequest} for all {@link CacheOperation} using - * the specified result value. + * Collect a {@link CachePutRequest} for every {@link CacheOperation} + * using the specified result value. * @param contexts the contexts to handle - * @param result the result value (never {@code null}) + * @param result the result value * @param putRequests the collection to update */ private void collectPutRequests(Collection contexts, diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java index 7c717714c7..3461dcdbc6 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -62,11 +62,13 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** - * A component provider that provides candidate components from a base package. Can - * use {@link CandidateComponentsIndex the index} if it is available of scans the - * classpath otherwise. Candidate components are identified by applying exclude and - * include filters. {@link AnnotationTypeFilter}, {@link AssignableTypeFilter} include - * filters on an annotation/superclass that are annotated with {@link Indexed} are + * A component provider that scans for candidate components starting from a + * specified base package. Can use the {@linkplain CandidateComponentsIndex component + * index}, if it is available, and scans the classpath otherwise. + * + *

Candidate components are identified by applying exclude and include filters. + * {@link AnnotationTypeFilter} and {@link AssignableTypeFilter} include filters + * for an annotation/target-type that is annotated with {@link Indexed} are * supported: if any other include filter is specified, the index is ignored and * classpath scanning is used instead. * @@ -201,7 +203,6 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC * {@link Controller @Controller} stereotype annotations. *

Also supports Jakarta EE's {@link jakarta.annotation.ManagedBean} and * JSR-330's {@link jakarta.inject.Named} annotations, if available. - * */ @SuppressWarnings("unchecked") protected void registerDefaultFilters() { @@ -305,7 +306,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC /** - * Scan the class path for candidate components. + * Scan the component index or class path for candidate components. * @param basePackage the package to check for annotated classes * @return a corresponding Set of autodetected bean definitions */ @@ -319,7 +320,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC } /** - * Determine if the index can be used by this instance. + * Determine if the component index can be used by this instance. * @return {@code true} if the index is available and the configuration of this * instance is supported by it, {@code false} otherwise * @since 5.0 @@ -460,8 +461,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC } } catch (Throwable ex) { - throw new BeanDefinitionStoreException( - "Failed to read candidate component class: " + resource, ex); + throw new BeanDefinitionStoreException("Failed to read candidate component class: " + resource, ex); } } } diff --git a/spring-core/src/main/java/org/springframework/util/StreamUtils.java b/spring-core/src/main/java/org/springframework/util/StreamUtils.java index 99d09eefe1..9d982f89a6 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java index 068a1c4578..1666daf420 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 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. @@ -43,7 +43,7 @@ public interface CallMetaDataProvider { /** * Initialize the database specific management of procedure column meta-data. - * This is only called for databases that are supported. This initialization + *

This is only called for databases that are supported. This initialization * can be turned off by specifying that column meta-data should not be used. * @param databaseMetaData used to retrieve database specific information * @param catalogName name of catalog to use (or {@code null} if none) @@ -55,30 +55,36 @@ public interface CallMetaDataProvider { void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @Nullable String catalogName, @Nullable String schemaName, @Nullable String procedureName) throws SQLException; + /** + * Get the call parameter meta-data that is currently used. + * @return a List of {@link CallParameterMetaData} + */ + List getCallParameterMetaData(); + /** * Provide any modification of the procedure name passed in to match the meta-data currently used. - * This could include altering the case. + *

This could include altering the case. */ @Nullable String procedureNameToUse(@Nullable String procedureName); /** * Provide any modification of the catalog name passed in to match the meta-data currently used. - * This could include altering the case. + *

This could include altering the case. */ @Nullable String catalogNameToUse(@Nullable String catalogName); /** * Provide any modification of the schema name passed in to match the meta-data currently used. - * This could include altering the case. + *

This could include altering the case. */ @Nullable String schemaNameToUse(@Nullable String schemaName); /** * Provide any modification of the catalog name passed in to match the meta-data currently used. - * The returned value will be used for meta-data lookups. This could include altering the case + *

The returned value will be used for meta-data lookups. This could include altering the case * used or providing a base catalog if none is provided. */ @Nullable @@ -86,7 +92,7 @@ public interface CallMetaDataProvider { /** * Provide any modification of the schema name passed in to match the meta-data currently used. - * The returned value will be used for meta-data lookups. This could include altering the case + *

The returned value will be used for meta-data lookups. This could include altering the case * used or providing a base schema if none is provided. */ @Nullable @@ -94,7 +100,7 @@ public interface CallMetaDataProvider { /** * Provide any modification of the column name passed in to match the meta-data currently used. - * This could include altering the case. + *

This could include altering the case. * @param parameterName name of the parameter of column */ @Nullable @@ -102,7 +108,7 @@ public interface CallMetaDataProvider { /** * Create a default out parameter based on the provided meta-data. - * This is used when no explicit parameter declaration has been made. + *

This is used when no explicit parameter declaration has been made. * @param parameterName the name of the parameter * @param meta meta-data used for this call * @return the configured SqlOutParameter @@ -111,7 +117,7 @@ public interface CallMetaDataProvider { /** * Create a default in/out parameter based on the provided meta-data. - * This is used when no explicit parameter declaration has been made. + *

This is used when no explicit parameter declaration has been made. * @param parameterName the name of the parameter * @param meta meta-data used for this call * @return the configured SqlInOutParameter @@ -120,7 +126,7 @@ public interface CallMetaDataProvider { /** * Create a default in parameter based on the provided meta-data. - * This is used when no explicit parameter declaration has been made. + *

This is used when no explicit parameter declaration has been made. * @param parameterName the name of the parameter * @param meta meta-data used for this call * @return the configured SqlParameter @@ -142,7 +148,7 @@ public interface CallMetaDataProvider { /** * Does this database support returning ResultSets as ref cursors to be retrieved with - * {@link java.sql.CallableStatement#getObject(int)} for the specified column. + * {@link java.sql.CallableStatement#getObject(int)} for the specified column? */ boolean isRefCursorSupported(); @@ -158,18 +164,12 @@ public interface CallMetaDataProvider { boolean isProcedureColumnMetaDataUsed(); /** - * Should we bypass the return parameter with the specified name. - * This allows the database specific implementation to skip the processing + * Should we bypass the return parameter with the specified name? + *

This allows the database specific implementation to skip the processing * for specific results returned by the database call. */ boolean byPassReturnParameter(String parameterName); - /** - * Get the call parameter meta-data that is currently used. - * @return a List of {@link CallParameterMetaData} - */ - List getCallParameterMetaData(); - /** * Does the database support the use of catalog name in procedure calls? */ diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index 3822fae85b..789351ff5e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -168,11 +168,6 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { return identifierNameToUse(parameterName); } - @Override - public boolean byPassReturnParameter(String parameterName) { - return false; - } - @Override public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { return new SqlOutParameter(parameterName, meta.getSqlType()); @@ -213,6 +208,11 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { return this.procedureColumnMetaDataUsed; } + @Override + public boolean byPassReturnParameter(String parameterName) { + return false; + } + /** * Specify whether the database supports the use of catalog name in procedure calls. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDataSource.java index 2bb62d1c3d..33e6c31d94 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/AbstractDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 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. @@ -75,10 +75,10 @@ public abstract class AbstractDataSource implements DataSource { throw new UnsupportedOperationException("setLogWriter"); } - - //--------------------------------------------------------------------- - // Implementation of JDBC 4.0's Wrapper interface - //--------------------------------------------------------------------- + @Override + public Logger getParentLogger() { + return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + } @Override @SuppressWarnings("unchecked") @@ -95,14 +95,4 @@ public abstract class AbstractDataSource implements DataSource { return iface.isInstance(this); } - - //--------------------------------------------------------------------- - // Implementation of JDBC 4.1's getParentLogger method - //--------------------------------------------------------------------- - - @Override - public Logger getParentLogger() { - return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java index 7204397820..a2a39f3aa1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 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. @@ -104,6 +104,16 @@ public class DelegatingDataSource implements DataSource, InitializingBean { return obtainTargetDataSource().getConnection(username, password); } + @Override + public int getLoginTimeout() throws SQLException { + return obtainTargetDataSource().getLoginTimeout(); + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException { + obtainTargetDataSource().setLoginTimeout(seconds); + } + @Override public PrintWriter getLogWriter() throws SQLException { return obtainTargetDataSource().getLogWriter(); @@ -115,20 +125,10 @@ public class DelegatingDataSource implements DataSource, InitializingBean { } @Override - public int getLoginTimeout() throws SQLException { - return obtainTargetDataSource().getLoginTimeout(); + public Logger getParentLogger() { + return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); } - @Override - public void setLoginTimeout(int seconds) throws SQLException { - obtainTargetDataSource().setLoginTimeout(seconds); - } - - - //--------------------------------------------------------------------- - // Implementation of JDBC 4.0's Wrapper interface - //--------------------------------------------------------------------- - @Override @SuppressWarnings("unchecked") public T unwrap(Class iface) throws SQLException { @@ -143,14 +143,4 @@ public class DelegatingDataSource implements DataSource, InitializingBean { return (iface.isInstance(this) || obtainTargetDataSource().isWrapperFor(iface)); } - - //--------------------------------------------------------------------- - // Implementation of JDBC 4.1's getParentLogger method - //--------------------------------------------------------------------- - - @Override - public Logger getParentLogger() { - return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java index cc71ba2c9d..a0c3945058 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -61,7 +61,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple /** * Specify the map of target DataSources, with the lookup key as key. - * The mapped value can either be a corresponding {@link javax.sql.DataSource} + *

The mapped value can either be a corresponding {@link javax.sql.DataSource} * instance or a data source name String (to be resolved via a * {@link #setDataSourceLookup DataSourceLookup}). *

The key can be of arbitrary type; this class implements the @@ -213,6 +213,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple return (iface.isInstance(this) || determineTargetDataSource().isWrapperFor(iface)); } + /** * Retrieve the current target DataSource. Determines the * {@link #determineCurrentLookupKey() current lookup key}, performs diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index 1f8904b62b..6e42108c96 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -353,6 +353,11 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar findInjectionMetadata(beanDefinition, beanType, beanName); } + @Override + public void resetBeanDefinition(String beanName) { + this.injectionMetadataCache.remove(beanName); + } + @Override public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); @@ -373,11 +378,6 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar return metadata; } - @Override - public void resetBeanDefinition(String beanName) { - this.injectionMetadataCache.remove(beanName); - } - @Override public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) { InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass(), pvs);