myeclipse配置spring

来源:互联网 发布:vue vendor.js 包过大 编辑:程序博客网 时间:2024/05/18 00:51

如何在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包。

wKiom1bEFxyQhndlAABBTwfLvTw768.png

3.今天刚看的Java视频里面是这样讲的,选中这几个jar包,右键,选择Build Path->Add to Path:

wKioL1bEGE7gecI4AACfBADv45g892.png

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类,进行测试。

0 0
原创粉丝点击