@@ -158,132 +158,5 @@ public class Client {
158
158
159
159
###### [ 代码] ( ../../../../../src/main/java/org/fade/pattern/cp/prototype/improve )
160
160
161
- #### 在Spring中的源码分析
162
-
163
- ###### [ 代码] ( ../../../../../src/main/java/org/fade/pattern/cp/prototype/spring )
164
-
165
- ``` xml
166
- <?xml version =" 1.0" encoding =" UTF-8" ?>
167
- <beans xmlns =" http://www.springframework.org/schema/beans"
168
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
169
- xsi : schemaLocation =" http://www.springframework.org/schema/beans
170
- http://www.springframework.org/schema/beans/spring-beans.xsd" >
171
-
172
- <bean id =" id01" class =" org.fade.pattern.cp.prototype.spring.Monster" scope =" prototype" />
173
-
174
- </beans >
175
- ```
176
-
177
- ``` java
178
- public class Monster {
179
-
180
- private Integer id = 10 ;
181
-
182
- private String nickName = " 牛魔王" ;
183
-
184
- private String skill = " 芭蕉扇" ;
185
-
186
- public Monster (){
187
-
188
- }
189
-
190
- public Monster (Integer id , String nickName , String skill ) {
191
- this . id = id;
192
- this . nickName = nickName;
193
- this . skill = skill;
194
- }
195
-
196
- public Integer getId () {
197
- return id;
198
- }
199
-
200
- public void setId (Integer id ) {
201
- this . id = id;
202
- }
203
-
204
- public String getNickName () {
205
- return nickName;
206
- }
207
-
208
- public void setNickName (String nickName ) {
209
- this . nickName = nickName;
210
- }
211
-
212
- public String getSkill () {
213
- return skill;
214
- }
215
-
216
- public void setSkill (String skill ) {
217
- this . skill = skill;
218
- }
219
-
220
- @Override
221
- public String toString () {
222
- return " Monster{" +
223
- " id=" + id +
224
- " , nickName='" + nickName + ' \' ' +
225
- " , skill='" + skill + ' \' ' +
226
- ' }' ;
227
- }
228
-
229
- }
230
-
231
- public class Prototype {
232
-
233
- public static void main (String [] args ) {
234
- ApplicationContext applicationContext = new FileSystemXmlApplicationContext (System . getProperty(" user.dir" )
235
- + " /src/main/java/org/fade/pattern/cp/prototype/spring/ApplicationContext.xml" );
236
- Object bean1 = applicationContext. getBean(" id01" );
237
- System . out. println(" bean1:" + bean1);
238
- Object bean2 = applicationContext. getBean(" id01" );
239
- System . out. println(" bean2:" + bean2);
240
- System . out. println(bean1== bean2);
241
- }
242
-
243
- }
244
- ```
245
-
246
- ###### 运行结果
247
-
248
- ```
249
- bean1:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
250
- bean2:Monster{id=10, nickName='牛魔王', skill='芭蕉扇'}
251
- false
252
- ```
253
-
254
- ###### DEBUG调试
255
-
256
- 1 . ###### 单击图示处打上断点
257
-
258
- ![ #1 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-39-02.png )
259
-
260
- 2 . ###### 右键点击图示1处,选择图示2处选项“Debug 'Prototype.main()'”
261
-
262
- ![ #2 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-41-59.png )
263
-
264
- 3 . ###### 等调试系统上线后,点击图示处选项“Step Into”
265
-
266
- ![ #3 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-45-52.png )
267
-
268
- 4 . ###### 再点击图示处选项“Step Over”
269
-
270
- ![ #4 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-47-16.png )
271
-
272
- 5 . ###### 当代码运行至下图所示时,再次点击选项“Step Into”
273
-
274
- ![ #5 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-49-03.png )
275
-
276
- 6 . ###### 当出现如下图所示内容时,点击“getBean”
277
-
278
- ![ #6 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-51-26.png )
279
-
280
- 7 . ###### 当出现如下图所示内容时,点击选项“Step Into”
281
-
282
- ![ #7 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-54-33.png )
283
-
284
-
285
- 8 . ###### 滚动页面,当代码为下图所示的内容时,可以发现此处Spring中确实采用了原型模式
286
-
287
- ![ #8 ] ( ../../../../img/pattern/cp/prototype/Snipaste_2021-02-15_15-56-21.png )
288
-
161
+ #### [ 在Spring中的源码分析] ( spring.md )
289
162
0 commit comments