学无先后,达者为师

网站首页 java综合 正文

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

更新时间: 2021-12-23 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");
    }

原文链接:https://blog.csdn.net/jovi_zhao/article/details/83010881

栏目分类
最近更新