在MyEclipse中使用Spring,跨出Spring伟大的一步

来源:互联网 发布:mac苹果手机铃声设置 编辑:程序博客网 时间:2024/06/11 10:00
1.建一个java web工程项目,名字是:blog.csdn.net.daliu

2.建俩个包,一个名字是org.spring.dao,另外一个是:org.spring.test

3.导入相应的jar包。可以在这里下载到相对应的包:
http://pan.baidu.com/s/1jf5sq

如下图:


4.在src目录下新建一个名字为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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"xsi:schemaLocation="        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"></beans>


5.在org.spring.test 下新建testCase.java文件,用于测试。

完整代码如下:

package org.spring.test;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class testCase {@Testpublic void test() {String config = "applicationContext.xml";ApplicationContext ac = new ClassPathXmlApplicationContext(config);System.out.println(ac);}}


在控制台出现以下的提示,说明配置成功!!




0 0