Eclipse搭建Spring开发环境

一、软件准备

1. Eclipse, 下载地址:http://www.eclipse.org,可下载3.6版本

2. SpringIde, 有两种安装方法,官网:http://www.springsource.org/node/489

3. Spring Framework: 下载地址:http://www.springsource.org/download (这里使用的是2.5.5,最新为3.0.5)

二、软件安装

1. 安装Eclipse,直接解压到某个目录即可,比如我的:E:\SpringDev\eclipse。(注意:使用Eclipse需要安装Java)

2.安装SpringIDE,这里介绍两种方法,一种在线更新:Help->intall new software,更新地址为:http://springide.org/updatesite


第二种方法,下载离线包:http://u.115.com/file/f97474c557,或者备份下载。下载之后把它解压到Eclipse安装目录下即可。

3. 将下载的spring-framework-2.5.5-with-dependencies.zip解压。将其中的spring.jar(dist 目录中)、commons-logging.jar(lib\jakarta-commons目录)、log4j-1.2.15.jar(lib \log4j目录)这三个文件复制到的”D:\java\Spring\lib” 目录中,然后在Eclipse中建立一个“Springlib”库,将那三个文件添加进“Springlib”库中。关于如何添加用户库参考:http://www.cnblogs.com/maplye/archive/2006/06/19/429404.html


这样就完成了基本配置。接下来我们新建一个例子。该例子属于《Spring In Action》书中的第一个例子。

三、Spring示例

1. 新建Spring Project,取名为HelloWorld。建好之后我们首先先导入用户库。


2. 新建interface: GreetingService:

?
1
2
3
4
5
package info.leyond.test;
 
public interface GreetingService {
   public void sayGreeting();
}

3. 实现该接口:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package info.leyond.test;
 
public class GreetingServiceImpl implements GreetingService {
   private String greeting;
 
   public GreetingServiceImpl() {}
 
   public GreetingServiceImpl(String greeting) {
     this .greeting = greeting;
   }
 
   public void sayGreeting() {
     System.out.println(greeting);
   }
 
   public void setGreeting(String greeting) {
     this .greeting = greeting;
   }
}

4.测试程序:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package info.leyond.test;
 
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
 
public class HelloApp {
   public static void main(String[] args) throws Exception {
     BeanFactory factory =
         new XmlBeanFactory( new ClassPathResource( "./info/leyond/test/hello.xml" ));
 
     GreetingService greetingService =
         (GreetingService) factory.getBean( "greetingService" );
 
     greetingService.sayGreeting();
   }
}

5. 注意上面的hello.xml,配置如下:

?
1
2
3
4
5
6
7
8
9
10
11
<? xml version = "1.0" encoding = "UTF-8" ?>
    xsi:schemaLocation="http://www.springframework.org/schema/beans
 
   < bean id = "greetingService"
       class = "info.leyond.test.GreetingServiceImpl" >
     < property name = "greeting" value = "Buenos Dias!" />
   </ bean >
</ beans >

6. 文件已经准备妥当。此刻看看项目中项目名称旁边是否有个S标记。如果没有,右击HelloWorld,在弹出菜单中选择“Add Spring Project Nature”即可。

7.右键HelloWorld,选择properties,然后Spring->bean support->Config Files:


之后就可以看到hello.xml,以及GreetingServiceImpl.java都挂上了S.


8.最后执行程序,显示如下:

Buenos Dias!

9. 例子代码下载:http://www.box.net/shared/q7b2xzvxrl

参考资料:

1. http://blog.csdn.net/srx/archive/2005/12/31/567455.aspx

2.http://blog.csdn.net/jawsy/archive/2006/01/06/571934.aspx

3. http://blog.csdn.net/javamxj/archive/2005/06/26/403413.aspx

4.http://www.cnblogs.com/maplye/archive/2006/06/19/429404.html


http://www.kuaipan.cn/file/id_49444196087502506.htm


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值