码迷,mamicode.com
首页 > 编程语言 > 详细

Spring 学习第一天

时间:2017-08-12 13:24:09      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:log   ges   9.png   world   打印   分享   nbsp   xmla   使用   

 

创建Spring 的配置文件

技术分享

技术分享

技术分享

点击完成之后,我们就在src目录下创建了一个spring的配置文件。

技术分享

 

修改Bean配置文件

技术分享技术分享

 

全类名:class="com.atguigu.spring.beans.HelloWorld",用反射的方式,由spring帮我们创建Helloworld这么一个对象,然后id="helloworld" 这里的id是用来标识对象helloworld的,而name="name" 就对应方法setName 中的name。

 技术分享

在这里,ApplicationContext 代表的就是spring的 IOC 容器;

ClassPathXmlApplicationContext表示的是:配置文件在类路径下,然后传入的是applicationContext.xml

 这里面的ctx.getBean("helloworld"); 中的helloworld就对应applicationContext.xml 下的bean id 技术分享

 

 通过上面两个打印helloworld的方法的对比,可以看出:

常规情况下,我们要使用一个类的话,要先new 一个类对象,然后再通过对象赋值,然后再调用对象的方法,如下图:

技术分享

 

使用了spring之后,我们就将创建对象,为对象赋值的工作交给spring,我们直接调用方法即可,如下图:

技术分享

 

Spring 学习第一天

标签:log   ges   9.png   world   打印   分享   nbsp   xmla   使用   

原文地址:http://www.cnblogs.com/ch-10/p/7349865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!