-
Notifications
You must be signed in to change notification settings - Fork 141
Update 10-Component-Scan.md #11
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,11 +68,12 @@ public class MyPersonComponent { | |
| > 其实这里的 `MyPersonComponent` 和之前三个 "依赖注入(DI)" 的类是完全不一样的 | ||
| > 对比一下,你会发现前三种DI都是有 sayHello()方法的,而这里的 `MyPersonComponent` 只是代替了 XML 的部分工作,本身并没有 sayHello方法。 | ||
|
|
||
| - 这里的 `MyPersonComponent` 用处:生成`MyServiceImpl` 的Bean对象,代替了 XML 的绝大部分工作,该类本身是和`MyServiceImpl`无关的(没有继承) | ||
| - 而之前的三种 依赖注入(DI) 方式都是通过 XML 来生成 `MyServiceImpl` 的Bean对象,类运行时就是 Bean 对象 | ||
|
|
||
| - 之前的三种 依赖注入(DI) 方式的实现都是: 由 Spring 容器通过 XML 来生成 `MyServiceImpl` 类的Bean对象(类本身就是 Spring 容器操作的对象) | ||
| - 而这里的 `MyPersonComponent` 类只是用来生成`MyServiceImpl` 的Bean对象,它是代替了 XML 的绝大部分工作(这个类本身和`MyServiceImpl`是没有继承关系,所以也没有 sayHello方法) | ||
|
|
||
| **本节代码示例** | ||
| ```Java | ||
| Main函数中的例子(命名稍微改动,请变通): | ||
| 写在Main函数里(命名稍微改动,请变通): | ||
|
||
| ApplicationContext ComponentContext = new ClassPathXmlApplicationContext("Component-scan.xml"); | ||
| MyServiceImpl service = ComponentContext.getBean("myService", MyServiceImpl.class); | ||
| System.out.println(service.sayHello()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要强调没有继承关系呢。。其实是没有任何关系啊,都不是一层层面的东西