首先添加两个jar包
spring.jar 和commons-logging.jar
让后再src文件夹下面添加一个beans.xml文件(开头,可以这样找,/doc/reference/html-single/index.html,让后搜索<beans)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>
添加一个test类
package junit.test;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringTest
{
@Test
public void instanceSpring()
{
ApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{"beans.xml"});
}
}
最后run as “juint-test”