1、引入Spring jar包
2、新建一个Person 接口和Person Bean
public interface PersonIService { public void helloSpring();}
import cn.server.PersonIService;public class PersonServiceImpl implements PersonIService { @Override public void helloSpring() { System.out.println("Hello Spring!"); }}3、将PersonBean在beans.xml中注入:
4、使用ClassPathXmlApplicationContext 解析beans.xml 并得到PersonBean对象
@Test public void test() { ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); PersonIService personIService=(PersonIService)ac.getBean("personIService"); personIService.helloSpring(); }