spring 优越性实践

来源:互联网 发布:阿里云1m带宽 是多少 编辑:程序博客网 时间:2024/05/28 15:19
public class OrderServiceTest {    public static void main(String[] args) {        // OrderServiceImpl order = new OrderServiceImpl();        // 1最常见创建实例        // PaymentService weixin = new WeiXinPaymentServiceImpl();        // 2自定义的方式-反射创建实例//      String payPath = "com.payment.impl.WeiXinPaymentServiceImpl";//      PaymentService pay = Class.forName(payPath);//      order.setPaymentService(pay);        // 3spring注入        // 通过文件路径来获取        ApplicationContext ac = new FileSystemXmlApplicationContext(                "src/applicationContext.xml");        OrderServiceImpl orderSe;        orderSe = (OrderServiceImpl)ac.getBean("orderService");        PaymentService s1 = (PaymentService) ac.getBean("paymentService");        System.out.println(orderSe.pay());    }
0 0
原创粉丝点击