File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ public static void main(String[] args) {
17
17
18
18
userService .test ();
19
19
20
+ // userFactoryBean真正的那个对象,也就是getObject得到的对象
21
+ System .out .println (context .getBean ("userFactoryBean" ));
22
+ // 得到FactoryBean自己的bean对象
23
+ System .out .println (context .getBean ("&userFactoryBean" ));
24
+
20
25
}
21
26
22
27
}
Original file line number Diff line number Diff line change
1
+ package org .yangushan .service ;
2
+
3
+ import org .springframework .beans .factory .FactoryBean ;
4
+ import org .springframework .stereotype .Component ;
5
+
6
+ /**
7
+ * created by yangushan
8
+ * 2024/3/17 11:40
9
+ */
10
+ @ Component
11
+ public class UserFactoryBean implements FactoryBean <User > {
12
+ @ Override
13
+ public User getObject () throws Exception {
14
+ return new User ();
15
+ }
16
+
17
+ @ Override
18
+ public Class <?> getObjectType () {
19
+ return User .class ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change 1
- org.yangushan.service.UserService=org.springframework.stereotype.Component
2
- org.yangushan.service.OrderService=org.springframework.stereotype.Component
1
+ # org.yangushan.service.UserService=org.springframework.stereotype.Component
2
+ # org.yangushan.service.OrderService=org.springframework.stereotype.Component
You can’t perform that action at this time.
0 commit comments