当前位置:主页 > 软件编程 > JAVA代码 >

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

您可能感兴趣的文章:

相关文章