Browse Source

Polishing

6.0.x
Juergen Hoeller 1 year ago
parent
commit
b5377ee9cf
  1. 12
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  2. 22
      spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java
  3. 4
      spring-web/src/main/java/org/springframework/http/CacheControl.java

12
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -121,16 +121,16 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable { implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
@Nullable @Nullable
private static Class<?> javaxInjectProviderClass; private static Class<?> jakartaInjectProviderClass;
static { static {
try { try {
javaxInjectProviderClass = jakartaInjectProviderClass =
ClassUtils.forName("jakarta.inject.Provider", DefaultListableBeanFactory.class.getClassLoader()); ClassUtils.forName("jakarta.inject.Provider", DefaultListableBeanFactory.class.getClassLoader());
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
// JSR-330 API not available - Provider interface simply not supported then. // JSR-330 API not available - Provider interface simply not supported then.
javaxInjectProviderClass = null; jakartaInjectProviderClass = null;
} }
} }
@ -1327,7 +1327,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
ObjectProvider.class == descriptor.getDependencyType()) { ObjectProvider.class == descriptor.getDependencyType()) {
return new DependencyObjectProvider(descriptor, requestingBeanName); return new DependencyObjectProvider(descriptor, requestingBeanName);
} }
else if (javaxInjectProviderClass == descriptor.getDependencyType()) { else if (jakartaInjectProviderClass == descriptor.getDependencyType()) {
return new Jsr330Factory().createDependencyProvider(descriptor, requestingBeanName); return new Jsr330Factory().createDependencyProvider(descriptor, requestingBeanName);
} }
else { else {
@ -1757,7 +1757,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* Return whether the bean definition for the given bean name has been * Return whether the bean definition for the given bean name has been
* marked as a primary bean. * marked as a primary bean.
* @param beanName the name of the bean * @param beanName the name of the bean
* @param beanInstance the corresponding bean instance (can be null) * @param beanInstance the corresponding bean instance (can be {@code null})
* @return whether the given bean qualifies as primary * @return whether the given bean qualifies as primary
*/ */
protected boolean isPrimary(String beanName, Object beanInstance) { protected boolean isPrimary(String beanName, Object beanInstance) {

22
spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -40,7 +40,7 @@ import org.springframework.util.ReflectionUtils;
/** /**
* Register the necessary reflection hints so that the specified type can be * Register the necessary reflection hints so that the specified type can be
* bound at runtime. Fields, constructors, properties and record components * bound at runtime. Fields, constructors, properties, and record components
* are registered, except for a set of types like those in the {@code java.} * are registered, except for a set of types like those in the {@code java.}
* package where just the type is registered. Types are discovered transitively * package where just the type is registered. Types are discovered transitively
* on properties and record components, and generic types are registered as well. * on properties and record components, and generic types are registered as well.
@ -54,8 +54,9 @@ public class BindingReflectionHintsRegistrar {
private static final String JACKSON_ANNOTATION = "com.fasterxml.jackson.annotation.JacksonAnnotation"; private static final String JACKSON_ANNOTATION = "com.fasterxml.jackson.annotation.JacksonAnnotation";
private static final boolean jacksonAnnotationPresent = ClassUtils.isPresent(JACKSON_ANNOTATION, private static final boolean jacksonAnnotationPresent =
BindingReflectionHintsRegistrar.class.getClassLoader()); ClassUtils.isPresent(JACKSON_ANNOTATION, BindingReflectionHintsRegistrar.class.getClassLoader());
/** /**
* Register the necessary reflection hints to bind the specified types. * Register the necessary reflection hints to bind the specified types.
@ -94,8 +95,7 @@ public class BindingReflectionHintsRegistrar {
registerRecordHints(hints, seen, recordComponent.getAccessor()); registerRecordHints(hints, seen, recordComponent.getAccessor());
} }
} }
typeHint.withMembers( typeHint.withMembers(MemberCategory.DECLARED_FIELDS,
MemberCategory.DECLARED_FIELDS,
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
for (Method method : clazz.getMethods()) { for (Method method : clazz.getMethods()) {
String methodName = method.getName(); String methodName = method.getName();
@ -132,8 +132,7 @@ public class BindingReflectionHintsRegistrar {
} }
private void registerPropertyHints(ReflectionHints hints, Set<Type> seen, @Nullable Method method, int parameterIndex) { private void registerPropertyHints(ReflectionHints hints, Set<Type> seen, @Nullable Method method, int parameterIndex) {
if (method != null && method.getDeclaringClass() != Object.class && if (method != null && method.getDeclaringClass() != Object.class && method.getDeclaringClass() != Enum.class) {
method.getDeclaringClass() != Enum.class) {
hints.registerMethod(method, ExecutableMode.INVOKE); hints.registerMethod(method, ExecutableMode.INVOKE);
MethodParameter methodParameter = MethodParameter.forExecutable(method, parameterIndex); MethodParameter methodParameter = MethodParameter.forExecutable(method, parameterIndex);
Type methodParameterType = methodParameter.getGenericParameterType(); Type methodParameterType = methodParameter.getGenericParameterType();
@ -191,13 +190,13 @@ public class BindingReflectionHintsRegistrar {
.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY) .from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
.stream(JACKSON_ANNOTATION) .stream(JACKSON_ANNOTATION)
.filter(MergedAnnotation::isMetaPresent) .filter(MergedAnnotation::isMetaPresent)
.forEach(action::accept); .forEach(action);
} }
private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation<Annotation> annotation) { private void registerHintsForClassAttributes(ReflectionHints hints, MergedAnnotation<Annotation> annotation) {
annotation.getRoot().asMap().forEach((key,value) -> { annotation.getRoot().asMap().forEach((attributeName, value) -> {
if (value instanceof Class<?> classValue && value != Void.class) { if (value instanceof Class<?> classValue && value != Void.class) {
if (key.equals("builder")) { if (attributeName.equals("builder")) {
hints.registerType(classValue, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, hints.registerType(classValue, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_DECLARED_METHODS); MemberCategory.INVOKE_DECLARED_METHODS);
} }
@ -208,6 +207,7 @@ public class BindingReflectionHintsRegistrar {
}); });
} }
/** /**
* Inner class to avoid a hard dependency on Kotlin at runtime. * Inner class to avoid a hard dependency on Kotlin at runtime.
*/ */

4
spring-web/src/main/java/org/springframework/http/CacheControl.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -393,7 +393,7 @@ public class CacheControl {
} }
private void appendDirective(StringBuilder builder, String value) { private void appendDirective(StringBuilder builder, String value) {
if (builder.length() > 0) { if (!builder.isEmpty()) {
builder.append(", "); builder.append(", ");
} }
builder.append(value); builder.append(value);

Loading…
Cancel
Save