Skip to content

Commit 9c04f43

Browse files
committed
✅ add SimpleIOCTest , add circular dependency
1 parent 0e41546 commit 9c04f43

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/test/java/com/dianpoint/summer/test/SimpleIOCTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.dianpoint.summer.beans.BeansException;
44
import com.dianpoint.summer.beans.NoSuchBeanDefinitionException;
55
import com.dianpoint.summer.context.ClassPathXmlApplicationContext;
6+
import com.dianpoint.summer.test.service.OtherTwoService;
67
import com.dianpoint.summer.test.service.SimpleService;
78

89
/**
@@ -12,10 +13,16 @@
1213
*/
1314
public class SimpleIOCTest {
1415

15-
1616
public static void main(String[] args) throws BeansException {
1717
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
1818
SimpleService simpleService = (SimpleService)applicationContext.getBean("simpleService");
1919
simpleService.sayHello();
20+
21+
System.out.println("==================");
22+
23+
OtherTwoService otherTwoService = (OtherTwoService)applicationContext.getBean("otherTwoService");
24+
otherTwoService.sayHello();
25+
otherTwoService.sayBye();
26+
2027
}
2128
}

src/test/java/com/dianpoint/summer/test/service/OtherOneService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class OtherOneService {
55
private OtherTwoService otherTwoService;
66

77
public void sayHello() {
8-
System.out.println("Other One Service");
8+
System.out.printf("%s: Other One Service %n", getClass().getName());
99
otherTwoService.sayHello();
1010
}
1111

src/test/java/com/dianpoint/summer/test/service/OtherTwoService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ public class OtherTwoService {
44

55
private SimpleService simpleService;
66

7-
void sayHello() {
8-
System.out.println("Other two Service");
7+
public void sayHello() {
8+
System.out.printf("%s: Other two Service%n", getClass().getName());
99
}
1010

11-
void sayBye(){
11+
public void sayBye() {
1212
simpleService.sayBye();
1313
}
1414

src/test/java/com/dianpoint/summer/test/service/SimpleServiceImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class SimpleServiceImpl implements SimpleService {
99

1010
private String propertyName;
1111

12-
private String name;
13-
private int age;
12+
private final String name;
13+
private final int age;
1414

1515
private OtherOneService otherOneService;
1616

@@ -21,17 +21,16 @@ public SimpleServiceImpl(String name, int age) {
2121

2222
@Override
2323
public void sayHello() {
24-
System.out.println("hello: " + propertyName);
2524
// 打印通过构造器方式注入的属性name 和 age
26-
System.out.printf("name:%s,age:%s%n", name, age);
27-
System.out.println("================");
25+
System.out.printf("name:%s, age:%s, propertyName:%s %n", name, age, propertyName);
2826

2927
otherOneService.sayHello();
28+
3029
}
3130

3231
@Override
3332
public void sayBye() {
34-
System.out.println("SimpleServiceImpl bye");
33+
System.out.printf("%s: bye bye%n", getClass().getName());
3534
}
3635

3736
public void setPropertyName(String propertyName) {

0 commit comments

Comments
 (0)