@@ -45,7 +45,7 @@ public ResponseEntity getBeans() {
45
45
}
46
46
47
47
@ GetMapping ("/prototypes/ctx" )
48
- public ResponseEntity getBeansFromCtx () {
48
+ public ResponseEntity getPrototypeBeansFromCtx () {
49
49
// 매번 새로운 PrototypeBean1 이 생성되어 Map::size() == 1 인 맵을 반환
50
50
StringBuilder result = new StringBuilder ("Getting PrototypeBeans1 from ctx\n " );
51
51
@@ -60,6 +60,25 @@ public ResponseEntity getBeansFromCtx() {
60
60
return ResponseEntity .ok (result );
61
61
}
62
62
63
+
64
+ @ GetMapping ("/prototypes/beans" )
65
+ public ResponseEntity getBeansFromCtx () {
66
+ StringBuilder result = new StringBuilder ();
67
+
68
+ String [] beanNames = ctx .getBeanDefinitionNames ();
69
+ for (String beanName : beanNames ) {
70
+ Object bean = ctx .getBean (beanName );
71
+ if (!bean .getClass ().getName ().startsWith ("demo" )) {
72
+ continue ;
73
+ }
74
+ String display = String .format ("%-30s : %-40s [%s]" , beanName , bean .getClass ().getName (), bean .toString ());
75
+ result .append (display )
76
+ .append ("\n " );
77
+ }
78
+
79
+ return ResponseEntity .ok (result .toString ());
80
+ }
81
+
63
82
@ GetMapping ("/prototype/{id}" )
64
83
public ResponseEntity getBean (@ PathVariable ("id" ) Long id ) {
65
84
logger .info ("Try to get bean id : {}" , id );
@@ -98,20 +117,11 @@ public ResponseEntity destroyBean(@PathVariable("id") Long id) {
98
117
return ResponseEntity .notFound ().build ();
99
118
}
100
119
101
- String result = null ;
120
+ bean = null ;
102
121
103
- try {
104
- result = bean . toString ();
122
+ System . gc ();
123
+ System . runFinalization ();
105
124
106
- if (bean instanceof DisposableBean ) {
107
- logger .info ("Can cast DisposableBean" );
108
- DisposableBean disposable = (DisposableBean ) bean ;
109
- disposable .destroy ();
110
- }
111
- } catch (Exception e ) {
112
- result = e .getMessage ();
113
- }
114
-
115
- return ResponseEntity .ok (result );
125
+ return ResponseEntity .ok ().build ();
116
126
}
117
127
}
0 commit comments