5353import org .springframework .beans .factory .BeanCreationException ;
5454import org .springframework .beans .factory .BeanFactory ;
5555import org .springframework .beans .factory .BeanFactoryAware ;
56- import org .springframework .beans .factory .BeanFactoryUtils ;
5756import org .springframework .beans .factory .InjectionPoint ;
5857import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
5958import org .springframework .beans .factory .UnsatisfiedDependencyException ;
7776import org .springframework .core .MethodParameter ;
7877import org .springframework .core .Ordered ;
7978import org .springframework .core .PriorityOrdered ;
80- import org .springframework .core .annotation .AnnotationAttributes ;
8179import org .springframework .core .annotation .AnnotationUtils ;
8280import org .springframework .core .annotation .MergedAnnotation ;
8381import org .springframework .core .annotation .MergedAnnotations ;
@@ -613,39 +611,10 @@ private MergedAnnotation<?> findAutowiredAnnotation(AccessibleObject ao) {
613611 * @return whether the annotation indicates that a dependency is required
614612 */
615613 protected boolean determineRequiredStatus (MergedAnnotation <?> ann ) {
616- return determineRequiredStatus (ann .<AnnotationAttributes > asMap (
617- mergedAnnotation -> new AnnotationAttributes (mergedAnnotation .getType ())));
618- }
619-
620- /**
621- * Determine if the annotated field or method requires its dependency.
622- * <p>A 'required' dependency means that autowiring should fail when no beans
623- * are found. Otherwise, the autowiring process will simply bypass the field
624- * or method when no beans are found.
625- * @param ann the Autowired annotation
626- * @return whether the annotation indicates that a dependency is required
627- * @deprecated since 5.2, in favor of {@link #determineRequiredStatus(MergedAnnotation)}
628- */
629- @ Deprecated
630- protected boolean determineRequiredStatus (AnnotationAttributes ann ) {
631- return (!ann .containsKey (this .requiredParameterName ) ||
614+ return (ann .getValue (this .requiredParameterName ).isEmpty () ||
632615 this .requiredParameterValue == ann .getBoolean (this .requiredParameterName ));
633616 }
634617
635- /**
636- * Obtain all beans of the given type as autowire candidates.
637- * @param type the type of the bean
638- * @return the target beans, or an empty Collection if no bean of this type is found
639- * @throws BeansException if bean retrieval failed
640- */
641- protected <T > Map <String , T > findAutowireCandidates (Class <T > type ) throws BeansException {
642- if (this .beanFactory == null ) {
643- throw new IllegalStateException ("No BeanFactory configured - " +
644- "override the getBeanOfType method or specify the 'beanFactory' property" );
645- }
646- return BeanFactoryUtils .beansOfTypeIncludingAncestors (this .beanFactory , type );
647- }
648-
649618 /**
650619 * Register the specified bean as dependent on the autowired beans.
651620 */
@@ -685,11 +654,10 @@ private abstract static class AutowiredElement extends InjectionMetadata.Injecte
685654
686655 protected final boolean required ;
687656
688- protected AutowiredElement (Member member , PropertyDescriptor pd , boolean required ) {
657+ protected AutowiredElement (Member member , @ Nullable PropertyDescriptor pd , boolean required ) {
689658 super (member , pd );
690659 this .required = required ;
691660 }
692-
693661 }
694662
695663
@@ -926,10 +894,8 @@ private static class AotContribution implements BeanRegistrationAotContribution
926894 this .candidateResolver = candidateResolver ;
927895 }
928896
929-
930897 @ Override
931- public void applyTo (GenerationContext generationContext ,
932- BeanRegistrationCode beanRegistrationCode ) {
898+ public void applyTo (GenerationContext generationContext , BeanRegistrationCode beanRegistrationCode ) {
933899 GeneratedClass generatedClass = generationContext .getGeneratedClasses ()
934900 .addForFeatureComponent ("Autowiring" , this .target , type -> {
935901 type .addJavadoc ("Autowiring for {@link $T}." , this .target );
@@ -1003,15 +969,13 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
1003969 (!required ) ? "forMethod" : "forRequiredMethod" );
1004970 code .add ("($S" , method .getName ());
1005971 if (method .getParameterCount () > 0 ) {
1006- code .add (", $L" ,
1007- generateParameterTypesCode (method .getParameterTypes ()));
972+ code .add (", $L" , generateParameterTypesCode (method .getParameterTypes ()));
1008973 }
1009974 code .add (")" );
1010975 AccessControl accessControl = AccessControl .forMember (method );
1011976 if (!accessControl .isAccessibleFrom (targetClassName )) {
1012977 hints .reflection ().registerMethod (method , ExecutableMode .INVOKE );
1013- code .add (".resolveAndInvoke($L, $L)" , REGISTERED_BEAN_PARAMETER ,
1014- INSTANCE_PARAMETER );
978+ code .add (".resolveAndInvoke($L, $L)" , REGISTERED_BEAN_PARAMETER , INSTANCE_PARAMETER );
1015979 }
1016980 else {
1017981 hints .reflection ().registerMethod (method , ExecutableMode .INTROSPECT );
@@ -1038,27 +1002,27 @@ private void registerHints(RuntimeHints runtimeHints) {
10381002 boolean required = autowiredElement .required ;
10391003 Member member = autowiredElement .getMember ();
10401004 if (member instanceof Field field ) {
1041- DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (
1042- field , required );
1005+ DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (field , required );
10431006 registerProxyIfNecessary (runtimeHints , dependencyDescriptor );
10441007 }
10451008 if (member instanceof Method method ) {
10461009 Class <?>[] parameterTypes = method .getParameterTypes ();
10471010 for (int i = 0 ; i < parameterTypes .length ; i ++) {
10481011 MethodParameter methodParam = new MethodParameter (method , i );
1049- DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (
1050- methodParam , required );
1012+ DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (methodParam , required );
10511013 registerProxyIfNecessary (runtimeHints , dependencyDescriptor );
10521014 }
10531015 }
10541016 });
10551017 }
10561018
10571019 private void registerProxyIfNecessary (RuntimeHints runtimeHints , DependencyDescriptor dependencyDescriptor ) {
1058- Class <?> proxyType = this .candidateResolver
1059- .getLazyResolutionProxyClass (dependencyDescriptor , null );
1060- if (proxyType != null && Proxy .isProxyClass (proxyType )) {
1061- runtimeHints .proxies ().registerJdkProxy (proxyType .getInterfaces ());
1020+ if (this .candidateResolver != null ) {
1021+ Class <?> proxyType =
1022+ this .candidateResolver .getLazyResolutionProxyClass (dependencyDescriptor , null );
1023+ if (proxyType != null && Proxy .isProxyClass (proxyType )) {
1024+ runtimeHints .proxies ().registerJdkProxy (proxyType .getInterfaces ());
1025+ }
10621026 }
10631027 }
10641028
0 commit comments