Skip to content

Commit 215712d

Browse files
committed
Revert "ClassPathXmlApplicationContext构造器的前两个方法调用部分注释"
1 parent cd42a8c commit 215712d

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
215215
@Nullable
216216
private Thread shutdownHook;
217217

218-
/*
219-
* 在 new 容器的时候,会将该资源初始化
220-
*/
221218
/** ResourcePatternResolver used by this context. */
222219
private ResourcePatternResolver resourcePatternResolver;
223220

@@ -252,7 +249,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
252249
* Create a new AbstractApplicationContext with no parent.
253250
*/
254251
public AbstractApplicationContext() {
255-
this.resourcePatternResolver = getResourcePatternResolver(); // 获取资源解析器
252+
this.resourcePatternResolver = getResourcePatternResolver();
256253
}
257254

258255
/**
@@ -261,7 +258,7 @@ public AbstractApplicationContext() {
261258
*/
262259
public AbstractApplicationContext(@Nullable ApplicationContext parent) {
263260
this();
264-
setParent(parent); // parent 默认为 null, 设置当前的 parent 参数为 null
261+
setParent(parent);
265262
}
266263

267264

@@ -492,7 +489,7 @@ LifecycleProcessor getLifecycleProcessor() throws IllegalStateException {
492489
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
493490
*/
494491
protected ResourcePatternResolver getResourcePatternResolver() {
495-
return new PathMatchingResourcePatternResolver(this); // 该解析器支持 Ant 风格,简单的 url 协议。例如:file:// 这种也可以解析。 同时传入 resourceLoader
492+
return new PathMatchingResourcePatternResolver(this);
496493
}
497494

498495

spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableConfigApplicationContext.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public void setConfigLocation(String location) {
7070
}
7171

7272
/**
73-
* @param locations 传入参数类型: classpath:/applicationContext.xml
7473
* Set the config locations for this application context.
7574
* <p>If not set, the implementation may use a default as appropriate.
7675
*/
@@ -79,7 +78,7 @@ public void setConfigLocations(@Nullable String... locations) {
7978
Assert.noNullElements(locations, "Config locations must not be null");
8079
this.configLocations = new String[locations.length];
8180
for (int i = 0; i < locations.length; i++) {
82-
this.configLocations[i] = resolvePath(locations[i]).trim(); // 如果传入的是多个路径,向数组中添加值。
81+
this.configLocations[i] = resolvePath(locations[i]).trim();
8382
}
8483
}
8584
else {
@@ -123,7 +122,7 @@ protected String[] getDefaultConfigLocations() {
123122
* @see org.springframework.core.env.Environment#resolveRequiredPlaceholders(String)
124123
*/
125124
protected String resolvePath(String path) {
126-
return getEnvironment().resolveRequiredPlaceholders(path); // 解析占位符 ${}
125+
return getEnvironment().resolveRequiredPlaceholders(path);
127126
}
128127

129128

spring-context/src/main/java/org/springframework/context/support/ClassPathXmlApplicationContext.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public ClassPathXmlApplicationContext(ApplicationContext parent) {
7676
}
7777

7878
/**
79-
* 我们手动创建容器一般会使用该方法,将传入一个 xml 文件的路径。
80-
*
8179
* Create a new ClassPathXmlApplicationContext, loading the definitions
8280
* from the given XML file and automatically refreshing the context.
8381
* @param configLocation resource location
@@ -126,11 +124,6 @@ public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh)
126124
}
127125

128126
/**
129-
* 真正执行的构造器方法,
130-
* configLocations:传入的 xml 文件路径,可以传入多个。
131-
* refresh:是否刷新容器,默认是 true
132-
* parent: 父容器
133-
*
134127
* Create a new ClassPathXmlApplicationContext with the given parent,
135128
* loading the definitions from the given XML files.
136129
* @param configLocations array of resource locations
@@ -145,10 +138,10 @@ public ClassPathXmlApplicationContext(
145138
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
146139
throws BeansException {
147140

148-
super(parent); // 调用一系列父类的构造器,最终调到 AbstractApplicationContext 的构造器
149-
setConfigLocations(configLocations); // 设置 xml 文件的路径
141+
super(parent);
142+
setConfigLocations(configLocations);
150143
if (refresh) {
151-
refresh(); // 刷新容器
144+
refresh();
152145
}
153146
}
154147

0 commit comments

Comments
 (0)