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

myeclipse中如何为一个项目配置spring

时间:2016-02-17 19:28:15      阅读:1163      评论:0      收藏:0      [点我收藏+]

标签:spring   配置   myeclipse   如何   jar包   

如何在myeclipse中为一个普通的项目导入spring框架呢?
1.新建一个工程,在src目录下,新建一个lib文件夹,存放spring所需要的jar包
2.导入springjar包:
commons-logging-1.1.1.jar

org.springframework.beans-3.1.1.RELEASE.jar    //springIoC(依赖注入)的基础实现。

org.springframework.context-3.1.1.RELEASE.jar   //spring 提供在基础 IoC 功能上的扩展服务,此外还提供许多企业级服务的支持,如 邮件服务、任务调度、JNDI定位、EJB 集成、远程访问、 缓存以及各种视图层框架的封装等。
org.springframework.core-3.1.1.RELEASE.jar      //spring3.1的核心工具包。

org.springframework.expression-3.1.1.RELEASE.jar    //spring 表达式语言。

org.springframework.asm-3.1.1.RELEASE.jar      //spring 独立的asm 程序,相比2.5版本,需要额外的asm.jar包。

技术分享

3.选中这几个jar包,右键,选择Build Path->Add to Path:

技术分享

4.在src下新建一个xml文件,命名为applicationContext.xml,作为spring的核心配置文件,通用代码如下:


<?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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-2.5.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<!--创建Bean,有指定的id,对应的class-->

<!--注意:此处的id是作为bean的标志名,调用bean时会用到,class必须为这个bean的类路径(包名.类名)-->
<bean id="hellobean" class="com.zjy.spring.beans.HelloWorld">
     <property name="name" value="ZJY"></property>
</bean>
 
</beans>

5.完成配置,建立bean类,进行测试。

本文出自 “11179738” 博客,请务必保留此出处http://11189738.blog.51cto.com/11179738/1742697

myeclipse中如何为一个项目配置spring

标签:spring   配置   myeclipse   如何   jar包   

原文地址:http://11189738.blog.51cto.com/11179738/1742697

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