53
53
import org .springframework .beans .factory .BeanCreationException ;
54
54
import org .springframework .beans .factory .BeanFactory ;
55
55
import org .springframework .beans .factory .BeanFactoryAware ;
56
- import org .springframework .beans .factory .BeanFactoryUtils ;
57
56
import org .springframework .beans .factory .InjectionPoint ;
58
57
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
59
58
import org .springframework .beans .factory .UnsatisfiedDependencyException ;
77
76
import org .springframework .core .MethodParameter ;
78
77
import org .springframework .core .Ordered ;
79
78
import org .springframework .core .PriorityOrdered ;
80
- import org .springframework .core .annotation .AnnotationAttributes ;
81
79
import org .springframework .core .annotation .AnnotationUtils ;
82
80
import org .springframework .core .annotation .MergedAnnotation ;
83
81
import org .springframework .core .annotation .MergedAnnotations ;
@@ -613,39 +611,10 @@ private MergedAnnotation<?> findAutowiredAnnotation(AccessibleObject ao) {
613
611
* @return whether the annotation indicates that a dependency is required
614
612
*/
615
613
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 () ||
632
615
this .requiredParameterValue == ann .getBoolean (this .requiredParameterName ));
633
616
}
634
617
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
-
649
618
/**
650
619
* Register the specified bean as dependent on the autowired beans.
651
620
*/
@@ -685,11 +654,10 @@ private abstract static class AutowiredElement extends InjectionMetadata.Injecte
685
654
686
655
protected final boolean required ;
687
656
688
- protected AutowiredElement (Member member , PropertyDescriptor pd , boolean required ) {
657
+ protected AutowiredElement (Member member , @ Nullable PropertyDescriptor pd , boolean required ) {
689
658
super (member , pd );
690
659
this .required = required ;
691
660
}
692
-
693
661
}
694
662
695
663
@@ -926,10 +894,8 @@ private static class AotContribution implements BeanRegistrationAotContribution
926
894
this .candidateResolver = candidateResolver ;
927
895
}
928
896
929
-
930
897
@ Override
931
- public void applyTo (GenerationContext generationContext ,
932
- BeanRegistrationCode beanRegistrationCode ) {
898
+ public void applyTo (GenerationContext generationContext , BeanRegistrationCode beanRegistrationCode ) {
933
899
GeneratedClass generatedClass = generationContext .getGeneratedClasses ()
934
900
.addForFeatureComponent ("Autowiring" , this .target , type -> {
935
901
type .addJavadoc ("Autowiring for {@link $T}." , this .target );
@@ -1003,15 +969,13 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
1003
969
(!required ) ? "forMethod" : "forRequiredMethod" );
1004
970
code .add ("($S" , method .getName ());
1005
971
if (method .getParameterCount () > 0 ) {
1006
- code .add (", $L" ,
1007
- generateParameterTypesCode (method .getParameterTypes ()));
972
+ code .add (", $L" , generateParameterTypesCode (method .getParameterTypes ()));
1008
973
}
1009
974
code .add (")" );
1010
975
AccessControl accessControl = AccessControl .forMember (method );
1011
976
if (!accessControl .isAccessibleFrom (targetClassName )) {
1012
977
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 );
1015
979
}
1016
980
else {
1017
981
hints .reflection ().registerMethod (method , ExecutableMode .INTROSPECT );
@@ -1038,27 +1002,27 @@ private void registerHints(RuntimeHints runtimeHints) {
1038
1002
boolean required = autowiredElement .required ;
1039
1003
Member member = autowiredElement .getMember ();
1040
1004
if (member instanceof Field field ) {
1041
- DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (
1042
- field , required );
1005
+ DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (field , required );
1043
1006
registerProxyIfNecessary (runtimeHints , dependencyDescriptor );
1044
1007
}
1045
1008
if (member instanceof Method method ) {
1046
1009
Class <?>[] parameterTypes = method .getParameterTypes ();
1047
1010
for (int i = 0 ; i < parameterTypes .length ; i ++) {
1048
1011
MethodParameter methodParam = new MethodParameter (method , i );
1049
- DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (
1050
- methodParam , required );
1012
+ DependencyDescriptor dependencyDescriptor = new DependencyDescriptor (methodParam , required );
1051
1013
registerProxyIfNecessary (runtimeHints , dependencyDescriptor );
1052
1014
}
1053
1015
}
1054
1016
});
1055
1017
}
1056
1018
1057
1019
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
+ }
1062
1026
}
1063
1027
}
1064
1028
0 commit comments