java的main方法中调用spring的service方式
作者:jovi_zhao
这篇文章主要介绍了在java的main方法中调用spring的service方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
main方法调用spring的service
将业务层类配置到Spring中:
<bean id="customerService" class="cn.itcast.crm.service.impl.CustomerServiceImpl"> </bean>
Spring的方式进行操作:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
CustomerService customerService = (CustomerService) applicationContext.getBean("customerService");
customerService.save(customer);
main方法调用spring的dao service方法
public static void main(String[] args) {
ApplicationContext context = new
ClassPathXmlApplicationContext("ApplicationContext.xml");
System.out.println("aaa");
// ServiceReportService service = (ServiceReportService)context.getBean("serviceReportService");
}
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
