Skip to content

Commit 2d3ad55

Browse files
committed
feat:trx
1 parent 1e9e8f4 commit 2d3ad55

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

spring-test/src/main/java/org/springframework/wx/AnnoAC.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.expression.spel.standard.SpelExpressionParser;
66
import org.springframework.expression.spel.support.StandardEvaluationContext;
77
import org.springframework.wx.beans4test.circularReference.A;
8+
import org.springframework.wx.beans4test.lazy.NotALazyBean;
89
import org.springframework.wx.beans4test.methodOveride.Student;
910
import 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
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)