Skip to content

Commit 1ca2814

Browse files
committed
test: Implement additional test cases for the FactoryBean
1 parent 93193cf commit 1ca2814

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

yangushan-test/src/main/java/org/yangushan/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public static void main(String[] args) {
1717

1818
userService.test();
1919

20+
// userFactoryBean真正的那个对象,也就是getObject得到的对象
21+
System.out.println(context.getBean("userFactoryBean"));
22+
// 得到FactoryBean自己的bean对象
23+
System.out.println(context.getBean("&userFactoryBean"));
24+
2025
}
2126

2227
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
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

0 commit comments

Comments
 (0)