一、普通方法实现
新建一个HelloWord类,编写下列代码。
2、Spring4之HelloWorld
新建一个Main类,编写下列代码,运行:
2、Spring4之HelloWorld

二、使用Spring实现
1、导包
2、Spring4之HelloWorld
2、编写Spring配置文件:applicationContext.xml
2、Spring4之HelloWorld
2、Spring4之HelloWorld
3、改写Main方法:
2、Spring4之HelloWorld

**运行结果:
2、Spring4之HelloWorld
最后,我们将Main方法后面两行注释掉,然后改写一下HelloWorld类,看会发生什么:
HelloWorld:
2、Spring4之HelloWorld
Main:
2、Spring4之HelloWorld
运行结果:
2、Spring4之HelloWorld

相关文章: