java的main方法中调用spring的service方式

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");
    }

以上为个人经验,希望能给大家一个参考,也希望大家多多支持云海天教程。