1.在applicationContext.xml文件中配置bean

<bean id="userService" class="com.niwotaxuexiba.UserServiceImpl"></bean>

2.创建一个AppliCationContext对象
ApplicationContext它是BeanFactory的一个子接口,我们在使用时使用的是AppliCationContext的实现类ClassPathXmlApplicationContext

Spring的使用步骤_Web开发

可以通过getBean(配置文件中id名称)来获取指定的对象。