1.配置pom.xml [java] view plain copy print ? <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> 2.配置bean testInterface可以进行手动配置或自动扫描 手动配置 spring配置文件配置: [html] view plain copy print ? <bean id="testInterface" class="com.xxx.TestInterfaceImpl"> </bean> 自动扫描 接口实现类中配置 [java] view plain copy print ? @Component public class TestInterfaceImpl implements TestInterface { spring配置文件配置 [html] view plain copy print ? <context:annotation-config/> <context:component-scan base-package="com.xxx.servlet"> </context:component-scan> 3.编写接口测试代码 [java] view plain copy print ? import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:applicationContext.xml") public class Test { @Resource TestInterface testInterface; @Test public void test1(){ testInterface.test1(1,2); }