|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
昨天开始接触spring这个框架,主要是跟着尚硅谷的佟刚老师的视频进行学习的。
视频地址http://edu.csdn.net/course/detail/852/11716?auto_start=1
来说说的第一天学习进展吧,主要写了一个helloward
首先需要下载eclipse,下载地址,百度。我的eclipse是eclipse Java EE IDE for web Developers,版本号4.6.3
1.配置spring开发工具插件:spring-tool-suite,这个插件是为了方便开发spring时,我们所需要的命名空间能够进行选择。
(不知道这样表达得清不清楚,反正这个插件的作用就是为了命名空间)
本人采用本地配置,配置步骤:
(1).打开 eclipse-->help-->Install new software
(2).点击 Install页面的add按钮,选择已下载的spring-tool-suite进行安装,直接next
(3).重启eclipse,开始也出现springIDE的选项,表示安装插件成功
2.导入spring的包
因为只是写spring的helloword,并不需要吧spring的包全都导进去
那么,选择那几个包进行导入呢?
如下图所示
除了这四个包之外,还要配置
commons-logging-1.2.jar这个包,这个包比较特别,它不是直接在spring包里的,要单独下载,下载地址可以自己百度,这个包要根据自己的eclipse版本来下载对应的包
全部导入,并add到lib中后,便如下图
那么我们开始写一个helloward吧。
创建一个helloward的bean
- package beans;
- public class HelloWard {
-
- private String name;
-
- public HelloWard() {
-
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void hello() {
-
- System.out.println("hello: "+name);
- }
- }
复制代码
一定要加set方法,理由在下面的xml文件作解析
开始配置spring的IOC容器,new-->other--->spring--->spring bean....命名空间
配置HelloWord bean
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
- <!-- 配置 Hello ward bean-->
- <bean id="helloWard" class="beans.HelloWard">
- <property name="name" value="Spring"></property>
- </bean>
- </beans>
复制代码
之后在main运行
- // 创建spring的IOC容器
- ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
- //根据IOC容器获取entity类的对象
- HelloWard helloWard = (HelloWard) act.getBean("helloWard");
- //调用方法
- helloWard.hello();
复制代码
OK,helloward完成。
|
-
spring配置成功
-
springIOC容器
-
spring4个包
|