java的main方法中调用spring的service方式
时间:2022-05-18 08:42:27|栏目:JAVA代码|点击: 次
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");
}


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 3java中-jar 与nohup的对比
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




