Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 10-Component-Scan.md #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Update 10-Component-Scan.md #11

wants to merge 4 commits into from

Conversation

sky5454
Copy link
Contributor

@sky5454 sky5454 commented Jul 31, 2019

No description provided.

- 而之前的三种 依赖注入(DI) 方式都是通过 XML 来生成 `MyServiceImpl` 的Bean对象,类运行时就是 Bean 对象

```Java
Main函数中的例子(命名稍微改动,请变通):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码例子是从前面 IoC 那部分拿的吗?我没太懂想表达什么意思...

> 其实这里的 `MyPersonComponent` 和之前三个 "依赖注入(DI)" 的类是完全不一样的
> 对比一下,你会发现前三种DI都是有 sayHello()方法的,而这里的 `MyPersonComponent` 只是代替了 XML 的部分工作,本身并没有 sayHello方法。

- 这里的 `MyPersonComponent` 用处:生成`MyServiceImpl` 的Bean对象,代替了 XML 的绝大部分工作,该类本身是和`MyServiceImpl`无关的(没有继承)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段跟前面一段我大概知道你想表达是什么了,但感觉文字上可以再梳理一下,现在读起来逻辑上感觉有点乱。

前面在讲 该类本身是和MyServiceImpl无关的(没有继承),后面说 而之前的三种 依赖注入(DI) 方式都是通过 XML 来生成,这没有逻辑上的对应性。。。

```Java
Main函数中的例子(命名稍微改动,请变通):
写在Main函数里(命名稍微改动,请变通):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个例子是想表达什么东西呢,在前面有一个类似的代码

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果你把前面的类都改了名字,就能发现这段示例挺重要的

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面是说这一节的前面吗。还是 IoC 那一节

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指的是:前面的 DI

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我没太明白这个示例是想干啥。它重要在哪儿,

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段跟 https://skyline75489.github.io/Heart-First-JavaWeb/7-First-Spring-Container.html 这里的最下面那段代码,不一回事吗

> 对比一下,你会发现前三种DI都是有 sayHello()方法的,而这里的 `MyPersonComponent` 只是代替了 XML 的部分工作,本身并没有 sayHello方法。

- 之前的三种 依赖注入(DI) 方式的实现都是: 由 Spring 容器通过 XML 来生成 `MyServiceImpl` 类的Bean对象(类本身就是 Spring 容器操作的对象)
- 而这里的 `MyPersonComponent` 类只是用来生成`MyServiceImpl` 的Bean对象,它是代替了 XML 的绝大部分工作(这个类本身和`MyServiceImpl`是没有继承关系,所以也没有 sayHello方法)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要强调没有继承关系呢。。其实是没有任何关系啊,都不是一层层面的东西

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants