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

以上為個人經驗,希望能給大傢一個參考,也希望大傢多多支持WalkonNet。

推薦閱讀: