歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Spring+RMI+Hibernate發布多個服務(接口)思路

Spring+RMI+Hibernate發布多個服務(接口)思路

日期:2017/3/1 9:53:37   编辑:Linux編程

spring+RMI+hibernate發布多個服務(接口)思路,在配置的時候如果是兩個服務,則發布兩個RmiServiceExporter的bean。

客戶端這邊也在配置文件中設置兩個bean定義RmiProxyFactoryBean。在調用的時候對不同的服務,使用不同的getBean。

例如:服務端的配置文件:
<!-- RMI service 01 -->
<bean id="logPersonService"
class="org.springframework.remoting.rmi.RmiServiceExporter">
<!-- RmiServiceExporter 對服務名沒有特殊要求 -->
<property name="serviceName"><value>LogPerson</value></property>
<property name="service"><ref bean="PersonTarget"/></property>
<property name="serviceInterface"><value>com.hibernate.ILogPerson</value></property>
<!-- 避免與默認的RMI注冊端口沖突,因此修改為1200 -->
<property name="registryPort"> <value>1200</value> </property>
</bean>
<!-- RMI service 02 -->
<bean id="BayService"
class="org.springframework.remoting.rmi.RmiServiceExporter">

<property name="serviceName"><value>Bay</value></property>
<property name="service"><ref bean="BayTarget"/></property>
<property name="serviceInterface"><value>com.hibernate.IBay</value></property>

<property name="registryPort"> <value>1200</value> </property>
</bean>
客戶端的配置文件:
<!-- RMI Client 01-->
<bean id="LogPerson"
class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"><value>rmi://192.168.25.10:1200/LogPerson</value></property>
<property name="serviceInterface"><value>com.hibernate.ILogPerson</value></property>
</bean>
<!-- RMI Client 02-->
<bean id="Bay"
class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl"><value>rmi://192.168.25.10:1200/Bay</value></property>
<property name="serviceInterface"><value>com.hibernate.IBay</value></property>
</bean>

主程序中調用的方法:
//獲得RMI服務
ILogPerson clientLog = (ILogPerson) cfactory.getBean("LogPerson");
IBay clientBay = (IBay) cfactory.getBean("Bay");
在做關聯類的時候報錯

問題:
Exception in thread "main" org.springframework.remoting.RemoteAccessException:
Could not access remote service [rmi://192.168.25.10:1199/BankService];
nested exception is java.rmi.MarshalException: error marshalling arguments;
nested exception is: java.io.NotSerializableException: springexample.hibernate.Account

at springexample.hibernate.TestClient.main(TestClient.java:40)
Caused by: java.rmi.MarshalException: error marshalling arguments; nested exception is:
Caused by: java.io.NotSerializableException: springexample.hibernate.Account

解決:
這個單詞的意思居然沒沒明白marshalling arguments
就是用到的實體類沒有從可以序列化類中繼承過來啦!

Copyright © Linux教程網 All Rights Reserved