java的main方法中调用spring的service方式
更新时间:2021年12月03日 12:00:28 作者: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"); }
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
一篇文章带你使用SpringBoot基于WebSocket的在线群聊实现
这篇文章主要介绍了一篇文章带你使用SpringBoot基于WebSocket的在线群聊实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-10-10还在用if(obj!=null)做非空判断,带你快速上手Optional
这篇文章主要介绍了还在用if(obj!=null)做非空判断,带你快速上手Optional,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-05-05
最新评论