File tree Expand file tree Collapse file tree 3 files changed +55
-2
lines changed
spring-test/src/main/java/org/springframework/wx Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 55import org .springframework .expression .spel .standard .SpelExpressionParser ;
66import org .springframework .expression .spel .support .StandardEvaluationContext ;
77import org .springframework .wx .beans4test .circularReference .A ;
8+ import org .springframework .wx .beans4test .lazy .NotALazyBean ;
89import org .springframework .wx .beans4test .methodOveride .Student ;
910import org .springframework .wx .beans4test .methodOveride .Teacher ;
1011
@@ -67,8 +68,11 @@ public static void main(String[] args) {
6768// System.out.println(value);
6869
6970 // 测试importSelector
70- AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext ("org.springframework.wx.importSelector" );
71- annotationConfigApplicationContext .getBean ("personL" );
71+ // AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext("org.springframework.wx.importSelector");
72+ // annotationConfigApplicationContext.getBean("personL");
73+ // 实现懒加载bean
74+ AnnotationConfigApplicationContext context4LazyTest = new AnnotationConfigApplicationContext ("org.springframework.wx.beans4test.lazy" );
75+ ((NotALazyBean )context4LazyTest .getBean ("notALazyBean" )).getIamALazyBean ().getaBeanNeedAName ();
7276
7377
7478 }
Original file line number Diff line number Diff line change 1+ package org .springframework .wx .beans4test .lazy ;
2+
3+ import org .springframework .stereotype .Component ;
4+
5+ /**
6+ * @author wuxin
7+ * @date 2023/03/03 16:19:49
8+ */
9+ @ Component
10+ public class IamALazyBean {
11+
12+
13+ private String aBeanNeedAName ;
14+
15+
16+ public IamALazyBean () {
17+ System .out .println ("懒加载bean的初始化" );
18+ }
19+
20+ public String getaBeanNeedAName () {
21+ return aBeanNeedAName ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package org .springframework .wx .beans4test .lazy ;
2+
3+ import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .context .annotation .Lazy ;
5+ import org .springframework .stereotype .Component ;
6+
7+ /**
8+ * @author wuxin
9+ * @date 2023/03/03 16:21:39
10+ */
11+ @ Component
12+ public class NotALazyBean {
13+
14+ @ Autowired
15+ @ Lazy
16+ private IamALazyBean iamALazyBean ;
17+
18+ public NotALazyBean () {
19+ System .out .println ("非懒bean的初始化" );
20+ }
21+
22+
23+ public IamALazyBean getIamALazyBean () {
24+ return iamALazyBean ;
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments