spring 的延迟加载

今天用spring的rmi,启动似乎不注册rmi服务。最后手工的加载bean,成了。

 

    晕,在配置头的时候设置default-lazy-init="true",延迟加载的说。

 

    顺便贴代码

    服务器端配置文件

<!--  服务  -->
     < bean  id ="myService"  class ="org.spring.rmi.yoara.MyServiceImpl" />
    
     <!--  RmiServiceExporter 此类封装了生成stub的方法,大大简化代码  -->
     < bean  id ="serviceExporter"  class ="org.springframework.remoting.rmi.RmiServiceExporter" >
         <!--  服务  -->
         < property  name ="service"  ref ="myService" />
         <!--  服务名  -->
         < property  name ="serviceName"  value ="MyService" />
         <!--  绑定服务的路径  -->
         < property  name ="serviceInterface"  value ="org.spring.rmi.yoara.MyService" />
         <!--  服务端口  -->
         < property  name ="registryPort"  value ="1199" />

    </bean> 

服务pojo随便写就成了。

 

    客户端配置文件

< bean  id ="goService"  class ="org.springframework.remoting.rmi.RmiProxyFactoryBean" >
         <!--  服务URL  -->
         < property  name ="serviceUrl"  value ="rmi://127.0.0.1:1199/MyService" />
         <!--  本地接口路径  -->
         < property  name ="serviceInterface"  value ="org.spring.rmi.yoara.MyService" />

    </bean> 

 客户端调用代码

测试连接:
//        try {
//            System.out.println(Naming.lookup("rmi://localhost:1199/MyService"));
//        } catch (Exception e) {
//            e.printStackTrace();
        }


第一种:

        ClassPathXmlApplicationContext cxc = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        MyService client = (MyService)cxc.getBean("goService");
        client.showInfo();

第二种:

//        RmiProxyFactoryBean proxy=new RmiProxyFactoryBean();            
//        proxy.setServiceInterface(MyService.class);
//        proxy.setServiceUrl("rmi://localhost:1199/MyService");
//        proxy.afterPropertiesSet();
//        MyService client=(MyService)proxy.getObject();    

//        client.showInfo(); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值