62
62
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
63
63
import org .springframework .beans .factory .support .RegisteredBean ;
64
64
import org .springframework .beans .factory .support .RootBeanDefinition ;
65
- import org .springframework .context .aot .ResourceFieldValueResolver ;
66
- import org .springframework .context .aot .ResourceMethodArgumentResolver ;
67
65
import org .springframework .core .BridgeMethodResolver ;
68
- import org .springframework .core .MethodParameter ;
69
66
import org .springframework .core .Ordered ;
70
67
import org .springframework .core .annotation .AnnotationUtils ;
71
68
import org .springframework .javapoet .ClassName ;
@@ -501,16 +498,9 @@ public Class<?> getTargetClass() {
501
498
return element .lookupType ;
502
499
}
503
500
@ Override
504
- public boolean isStatic () {
505
- return false ;
506
- }
507
- @ Override
508
501
public Object getTarget () {
509
502
return getResource (element , requestingBeanName );
510
503
}
511
- @ Override
512
- public void releaseTarget (Object target ) {
513
- }
514
504
};
515
505
516
506
ProxyFactory pf = new ProxyFactory ();
@@ -655,12 +645,23 @@ public final Class<?> getLookupType() {
655
645
*/
656
646
public final DependencyDescriptor getDependencyDescriptor () {
657
647
if (this .isField ) {
658
- return new LookupDependencyDescriptor ((Field ) this .member , this .lookupType );
648
+ return new ResourceElementResolver .LookupDependencyDescriptor (
649
+ (Field ) this .member , this .lookupType , isLazyLookup ());
659
650
}
660
651
else {
661
- return new LookupDependencyDescriptor ((Method ) this .member , this .lookupType );
652
+ return new ResourceElementResolver .LookupDependencyDescriptor (
653
+ (Method ) this .member , this .lookupType , isLazyLookup ());
662
654
}
663
655
}
656
+
657
+ /**
658
+ * Determine whether this dependency is marked for lazy lookup.
659
+ * The default is {@code false}.
660
+ * @since 6.1.2
661
+ */
662
+ boolean isLazyLookup () {
663
+ return false ;
664
+ }
664
665
}
665
666
666
667
@@ -707,6 +708,11 @@ protected Object getResourceToInject(Object target, @Nullable String requestingB
707
708
return (this .lazyLookup ? buildLazyResourceProxy (this , requestingBeanName ) :
708
709
getResource (this , requestingBeanName ));
709
710
}
711
+
712
+ @ Override
713
+ boolean isLazyLookup () {
714
+ return this .lazyLookup ;
715
+ }
710
716
}
711
717
712
718
@@ -753,6 +759,11 @@ protected Object getResourceToInject(Object target, @Nullable String requestingB
753
759
return (this .lazyLookup ? buildLazyResourceProxy (this , requestingBeanName ) :
754
760
getResource (this , requestingBeanName ));
755
761
}
762
+
763
+ @ Override
764
+ boolean isLazyLookup () {
765
+ return this .lazyLookup ;
766
+ }
756
767
}
757
768
758
769
@@ -812,30 +823,6 @@ else if (this.isDefaultName && !StringUtils.hasLength(this.mappedName)) {
812
823
}
813
824
814
825
815
- /**
816
- * Extension of the DependencyDescriptor class,
817
- * overriding the dependency type with the specified resource type.
818
- */
819
- private static class LookupDependencyDescriptor extends DependencyDescriptor {
820
-
821
- private final Class <?> lookupType ;
822
-
823
- public LookupDependencyDescriptor (Field field , Class <?> lookupType ) {
824
- super (field , true );
825
- this .lookupType = lookupType ;
826
- }
827
-
828
- public LookupDependencyDescriptor (Method method , Class <?> lookupType ) {
829
- super (new MethodParameter (method , 0 ), true );
830
- this .lookupType = lookupType ;
831
- }
832
-
833
- @ Override
834
- public Class <?> getDependencyType () {
835
- return this .lookupType ;
836
- }
837
- }
838
-
839
826
/**
840
827
* {@link BeanRegistrationAotContribution} to inject resources on fields and methods.
841
828
*/
@@ -924,11 +911,11 @@ private CodeBlock generateMethodStatementForField(ClassName targetClassName,
924
911
925
912
private CodeBlock generateFieldResolverCode (Field field , LookupElement lookupElement ) {
926
913
if (lookupElement .isDefaultName ) {
927
- return CodeBlock .of ("$T.$L($S)" , ResourceFieldValueResolver .class ,
914
+ return CodeBlock .of ("$T.$L($S)" , ResourceElementResolver .class ,
928
915
"forField" , field .getName ());
929
916
}
930
917
else {
931
- return CodeBlock .of ("$T.$L($S, $S)" , ResourceFieldValueResolver .class ,
918
+ return CodeBlock .of ("$T.$L($S, $S)" , ResourceElementResolver .class ,
932
919
"forField" , field .getName (), lookupElement .getName ());
933
920
}
934
921
}
@@ -940,7 +927,7 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
940
927
AccessControl accessControl = AccessControl .forMember (method );
941
928
if (!accessControl .isAccessibleFrom (targetClassName )) {
942
929
hints .reflection ().registerMethod (method , ExecutableMode .INVOKE );
943
- return CodeBlock .of ("$L.resolveAndInvoke ($L, $L)" , resolver ,
930
+ return CodeBlock .of ("$L.resolveAndSet ($L, $L)" , resolver ,
944
931
REGISTERED_BEAN_PARAMETER , INSTANCE_PARAMETER );
945
932
}
946
933
hints .reflection ().registerMethod (method , ExecutableMode .INTROSPECT );
@@ -951,11 +938,11 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
951
938
952
939
private CodeBlock generateMethodResolverCode (Method method , LookupElement lookupElement ) {
953
940
if (lookupElement .isDefaultName ) {
954
- return CodeBlock .of ("$T.$L($S, $T.class)" , ResourceMethodArgumentResolver .class ,
941
+ return CodeBlock .of ("$T.$L($S, $T.class)" , ResourceElementResolver .class ,
955
942
"forMethod" , method .getName (), lookupElement .getLookupType ());
956
943
}
957
944
else {
958
- return CodeBlock .of ("$T.$L($S, $T.class, $S)" , ResourceMethodArgumentResolver .class ,
945
+ return CodeBlock .of ("$T.$L($S, $T.class, $S)" , ResourceElementResolver .class ,
959
946
"forMethod" , method .getName (), lookupElement .getLookupType (), lookupElement .getName ());
960
947
}
961
948
}
0 commit comments