为了方面,直接使用eclipse,创建maven工程,创建成功之后
一、修改pom.xml,为了方面我就把Spring相关的jar包都引用了
4.0.0 com.qunar studyspring 0.0.1-SNAPSHOT jar studyspring http://maven.apache.org UTF-8 3.0.5.RELEASE junit junit 4.10 test asm asm-commons 2.2.3 asm asm 2.2.3 org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-orm ${spring.version} org.springframework spring-jdbc ${spring.version} org.springframework spring-context ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-expression ${spring.version} org.springframework spring-test ${spring.version} org.springframework spring-tx ${spring.version} org.springframework spring-webmvc ${spring.version} net.sourceforge.cglib com.springsource.net.sf.cglib 2.1.3
二、载入spring.xml文件
三、编写测试代码
package com.qunar.studyspring;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.qunar.studyspring.Service.IPersonService;public class SpringTest { @Test public void instanceSpring(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); IPersonService personService = (IPersonService) ctx.getBean("personService"); personService.save(); }}
代码已经上传,下载地址: