首页 > 代码库 > Spring获取bean

Spring获取bean

1.在spring-servlet.xml中配置

<!--业务类的配置-->
<bean id="locationTaskService" class="com.location.service.LocationTaskServiceImpl"></bean>

2.添加获取bean的代码

ApplicationContext ac=new ClassPathXmlApplicationContext("spring-servlet.xml");
LocationTaskService cd=(LocationTaskService) ac.getBean("locationTaskService");

Spring获取bean