Polishing

This commit is contained in:
Juergen Hoeller 2024-02-20 15:42:15 +01:00
parent 85c9279431
commit 93f0ec2fa1
3 changed files with 13 additions and 12 deletions

View File

@ -282,7 +282,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
} }
if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) && if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) &&
expectedValue instanceof String name && bdHolder.matchesName(name)) { expectedValue instanceof String name && bdHolder.matchesName(name)) {
// Fall back on bean name (or alias) match // Finally, check bean name (or alias) match
continue; continue;
} }
if (actualValue == null && qualifier != null) { if (actualValue == null && qualifier != null) {
@ -333,8 +333,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
*/ */
@Override @Override
public boolean hasQualifier(DependencyDescriptor descriptor) { public boolean hasQualifier(DependencyDescriptor descriptor) {
for (Annotation ann : descriptor.getAnnotations()) { for (Annotation annotation : descriptor.getAnnotations()) {
if (isQualifier(ann.annotationType())) { if (isQualifier(annotation.annotationType())) {
return true; return true;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 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.
@ -81,6 +81,7 @@ import java.lang.annotation.Target;
* @see Bean * @see Bean
* @see ComponentScan * @see ComponentScan
* @see org.springframework.stereotype.Component * @see org.springframework.stereotype.Component
* @see org.springframework.beans.factory.config.BeanDefinition#setPrimary
*/ */
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -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.
@ -59,8 +59,8 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
void generateApplicationContextWithAutowiring() { void generateApplicationContextWithAutowiring() {
GenericApplicationContext context = new AnnotationConfigApplicationContext(); GenericApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBeanDefinition("autowiredComponent", new RootBeanDefinition(AutowiredComponent.class)); context.registerBeanDefinition("autowiredComponent", new RootBeanDefinition(AutowiredComponent.class));
context.registerBeanDefinition("number", BeanDefinitionBuilder.rootBeanDefinition(Integer.class, "valueOf") context.registerBeanDefinition("number", BeanDefinitionBuilder.rootBeanDefinition(
.addConstructorArgValue("42").getBeanDefinition()); Integer.class, "valueOf").addConstructorArgValue("42").getBeanDefinition());
compile(context, (hints, invocations) -> assertThat(invocations).match(hints)); compile(context, (hints, invocations) -> assertThat(invocations).match(hints));
} }
@ -89,8 +89,10 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
compile(context, (hints, invocations) -> assertThat(invocations).match(hints)); compile(context, (hints, invocations) -> assertThat(invocations).match(hints));
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({"rawtypes", "unchecked"})
private void compile(GenericApplicationContext applicationContext, BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) { private void compile(GenericApplicationContext applicationContext,
BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) {
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator(); ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
TestGenerationContext generationContext = new TestGenerationContext(); TestGenerationContext generationContext = new TestGenerationContext();
generator.processAheadOfTime(applicationContext, generationContext); generator.processAheadOfTime(applicationContext, generationContext);
@ -107,17 +109,15 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
}); });
} }
public interface Destroyable { public interface Destroyable {
@PreDestroy @PreDestroy
default void destroy() { default void destroy() {
} }
} }
public static class InheritedDestroy implements Destroyable { public static class InheritedDestroy implements Destroyable {
} }
} }