Skip to content

Commit

Permalink
代码框格式调整
Browse files Browse the repository at this point in the history
  • Loading branch information
Vip-Augus committed Jun 14, 2019
1 parent 2488b2f commit 12b6562
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
34 changes: 17 additions & 17 deletions spring-analysis-note/note/2019-06-08-spring-analysis-note-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ClassPathXmlApplicationContext

构造器的代码:

``` {.java}
``` java
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {
Expand All @@ -82,7 +82,7 @@ public ClassPathXmlApplicationContext(

> org.springframework.context.support.AbstractRefreshableConfigApplicationContext
``` {.java}
``` java
public void setConfigLocations(@Nullable String... locations) {
if (locations != null) {
Assert.noNullElements(locations, "Config locations must not be null");
Expand All @@ -104,7 +104,7 @@ public void setConfigLocations(@Nullable String... locations) {
`new ClassPathXmlApplicationContext("classpath:config.xml");`,就需要解析
`classpath`,变成正确路径。

``` {.java}
``` java
protected String resolvePath(String path) {
return getEnvironment().resolveRequiredPlaceholders(path);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ protected String resolvePath(String path) {

② 在代码启动时设置

``` {.java}
``` java
context.getEnvironment().setActiveProfiles("test");
```

Expand All @@ -183,7 +183,7 @@ context.getEnvironment().setActiveProfiles("test");
最终在 `StandardEnvironment` 使用 `CopyOnWriteArrayList`
数组进行属性存储

``` {.java}
``` java
protected void customizePropertySources(MutablePropertySources propertySources) {
propertySources.addLast(new MapPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties()));
propertySources.addLast(new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment()));
Expand All @@ -196,7 +196,7 @@ protected void customizePropertySources(MutablePropertySources propertySources)

到时这些参数就能在启动的应用中,通过上下文 `context` 进行获取

``` {.java}
``` java
((MutablePropertySources)((StandardEnvironment)context.environment).propertySources).propertySourceList
```

Expand All @@ -210,7 +210,7 @@ Bean 的解析和注册

> AbstractApplicationContext.refresh()
``` {.java}
``` java
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing. (为更新准备上下文,设定一些标志)
Expand Down Expand Up @@ -270,7 +270,7 @@ public void refresh() throws BeansException, IllegalStateException {

> org.springframework.core.env.AbstractPropertyResolver\#validateRequiredProperties
``` {.java}
``` java
public void validateRequiredProperties() {
MissingRequiredPropertiesException ex = new MissingRequiredPropertiesException();
for (String key : this.requiredProperties) {
Expand Down Expand Up @@ -298,7 +298,7 @@ public void validateRequiredProperties() {

> org.springframework.context.support.AbstractRefreshableApplicationContext\#refreshBeanFactory
``` {.java}
``` java
protected final void refreshBeanFactory() throws BeansException {
// 在更新时,如果发现已经存在,将会把之前的 bean 清理掉,并且关闭老 bean 容器
if (hasBeanFactory()) {
Expand Down Expand Up @@ -332,7 +332,7 @@ protected final void refreshBeanFactory() throws BeansException {

> org.springframework.context.support.AbstractRefreshableApplicationContext\#customizeBeanFactory
``` {.java}
``` java
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
if (this.allowBeanDefinitionOverriding != null) {
// 默认是 false,不允许覆盖
Expand Down Expand Up @@ -370,7 +370,7 @@ protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
**核心方法是这两行**

``` {.java}
``` java
public int loadBeanDefinitions(String location, @Nullable Set<Resource> actualResources) throws BeanDefinitionStoreException {
// 获取资源文件(资源加载器从路径识别资源文件)
Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location)
Expand All @@ -391,7 +391,7 @@ public int loadBeanDefinitions(String location, @Nullable Set<Resource> actualRe

> org.springframework.beans.factory.xml.XmlBeanDefinitionReader\#loadBeanDefinitions(org.springframework.core.io.support.EncodedResource)
``` {.java}
``` java
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
// 注释 1.7 从资源文件中获取输入流
InputStream inputStream = encodedResource.getResource().getInputStream();
Expand All @@ -413,7 +413,7 @@ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefin

> org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader\#parseDefaultElement
``` {.java}
``` java
private void parseDefaultElement(Element ele, BeanDefinitionParserDelegate delegate) {
if (delegate.nodeNameEquals(ele, IMPORT_ELEMENT)) {
importBeanDefinitionResource(ele);
Expand All @@ -440,7 +440,7 @@ private void parseDefaultElement(Element ele, BeanDefinitionParserDelegate deleg
> org.springframework.beans.factory.xml.BeanDefinitionParserDelegate\#parseBeanDefinitionElement(org.w3c.dom.Element,
> org.springframework.beans.factory.config.BeanDefinition)
``` {.java}
``` java
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) {
// 获取 ID 属性
String id = ele.getAttribute(ID_ATTRIBUTE);
Expand Down Expand Up @@ -508,7 +508,7 @@ public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable Be
> java.lang.String,
> org.springframework.beans.factory.config.BeanDefinition)
``` {.java}
``` java
public AbstractBeanDefinition parseBeanDefinitionElement(
Element ele, String beanName, @Nullable BeanDefinition containingBean) {
AbstractBeanDefinition bd = createBeanDefinition(className, parent);
Expand All @@ -532,7 +532,7 @@ public AbstractBeanDefinition parseBeanDefinitionElement(
> BeanDefinitionReaderUtils.createBeanDefinition(parentName, className,
> this.readerContext.getBeanClassLoader())
``` {.java}
``` java
public static AbstractBeanDefinition createBeanDefinition(
@Nullable String parentName, @Nullable String className, @Nullable ClassLoader classLoader) throws ClassNotFoundException {
GenericBeanDefinition bd = new GenericBeanDefinition();
Expand All @@ -559,7 +559,7 @@ public static AbstractBeanDefinition createBeanDefinition(
> org.springframework.beans.factory.config.BeanDefinitionHolder,
> org.springframework.beans.factory.config.BeanDefinition)
``` {.java}
``` java
public BeanDefinitionHolder decorateBeanDefinitionIfRequired(
Element ele, BeanDefinitionHolder definitionHolder, @Nullable BeanDefinition containingBd) {
// 方法中的第三个参数是父类 bean
Expand Down
10 changes: 5 additions & 5 deletions spring-analysis-note/note/2019-06-14-spring-analysis-note-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

先看源码是如何区分这两者:

``` {.java}
``` java
protected void parseBeanDefinitions(Element root, BeanDefinitionParserDelegate delegate) {
if (delegate.isDefaultNamespace(root)) {
// 注释 1.12 遍历 doc 中的节点列表
Expand Down Expand Up @@ -81,7 +81,7 @@ Bean 标签解析入口

定位到上面第三个方法 `processBeanDefinition(ele, delegate)`

``` {.java}
``` java
protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {
// 注释 1.15 解析 bean 名称的元素
BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);
Expand Down Expand Up @@ -239,7 +239,7 @@ protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate d

具体解析在这个方法中:

``` {.java}
``` java
/**
* 注释 2.8 解析 构造函数 子元素
* Parse constructor-arg sub-elements of the given bean element.
Expand Down Expand Up @@ -315,7 +315,7 @@ public void parseConstructorArgElements(Element beanEle, BeanDefinition bd) {
例如我们定义了一个抽象类 `AbstractBook`,有两个具体实现类 `Book1`
`Book2`,如果使用代码:

``` {.java}
``` java
@Autowired
private AbstractBook book;
```
Expand All @@ -334,7 +334,7 @@ private AbstractBook book;

② 使用 `@Qualifier("beanNeame")`

``` {.java}
``` java
@Qualifier("book1")
private AbstractBook book;
```
Expand Down

0 comments on commit 12b6562

Please sign in to comment.