发表于: 2020-06-16 23:53:12
1 1715
今天完成的事情:
重新整合了下代码
springserviceA
<bean id="helloWorld" class="com.ptteng.RMI.HelloWorldImp"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="serviceExporterA" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="helloWorld" />
<property name="serviceName" value="helloA"></property>
<property name="serviceInterface" value="com.ptteng.RMI.HelloWorld"></property>
<property name="registryPort" value="8888"></property>
</bean>
<bean id="accountServiceImpl" class="com.ptteng.service.serviceImpl.accountServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="accountA" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="accountServiceImpl" />
<property name="serviceName" value="accountA"></property>
<property name="serviceInterface" value="com.ptteng.service.accountService"></property>
<property name="registryPort" value="8888"></property>
</bean>
<bean id="companyServiceImpl" class="com.ptteng.service.serviceImpl.companyServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="companyA" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="companyServiceImpl" />
<property name="serviceName" value="companyA"></property>
<property name="serviceInterface" value="com.ptteng.service.companyService"></property>
<property name="registryPort" value="8888"></property>
</bean>
<bean id="professionServiceImpl" class="com.ptteng.service.serviceImpl.professionServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="professionA" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="professionServiceImpl" />
<property name="serviceName" value="professionA"></property>
<property name="serviceInterface" value="com.ptteng.service.professionService"></property>
<property name="registryPort" value="8888"></property>
</bean>
<bean id="studentServiceImpl" class="com.ptteng.service.serviceImpl.studentServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="studentA" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="studentServiceImpl" />
<property name="serviceName" value="studentA"></property>
<property name="serviceInterface" value="com.ptteng.service.studentService"></property>
<property name="registryPort" value="8888"></property>
</bean>
springserviceB 端口和名字不一样
代表2个服务
<bean id="helloWorld" class="com.ptteng.RMI.HelloWorldImp"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="serviceExporterB" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="helloWorld" />
<property name="serviceName" value="helloB"></property>
<property name="serviceInterface" value="com.ptteng.RMI.HelloWorld"></property>
<property name="registryPort" value="8887"></property>
</bean>
<bean id="accountServiceImpl" class="com.ptteng.service.serviceImpl.accountServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="accountB" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="accountServiceImpl" />
<property name="serviceName" value="accountB"></property>
<property name="serviceInterface" value="com.ptteng.service.accountService"></property>
<property name="registryPort" value="8887"></property>
</bean>
<bean id="companyServiceImpl" class="com.ptteng.service.serviceImpl.companyServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="companyB" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="companyServiceImpl" />
<property name="serviceName" value="companyB"></property>
<property name="serviceInterface" value="com.ptteng.service.companyService"></property>
<property name="registryPort" value="8887"></property>
</bean>
<bean id="professionServiceImpl" class="com.ptteng.service.serviceImpl.professionServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="professionB" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="professionServiceImpl" />
<property name="serviceName" value="professionB"></property>
<property name="serviceInterface" value="com.ptteng.service.professionService"></property>
<property name="registryPort" value="8887"></property>
</bean>
<bean id="studentServiceImpl" class="com.ptteng.service.serviceImpl.studentServiceImpl"></bean>
<!-- 将一个类发布为一个RMI服务 -->
<bean id="studentB" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="studentServiceImpl" />
<property name="serviceName" value="studentB"></property>
<property name="serviceInterface" value="com.ptteng.service.studentService"></property>
<property name="registryPort" value="8887"></property>
</bean>
springClint 客户端
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<!-- 客户端A -->
<bean id="HelloWorldClientA" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.RMI.HelloWorld"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8888/helloA"></property>
</bean>
<bean id="StudentClientA" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.studentMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8088/studentA"></property>
</bean>
<bean id="companyClientA" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.companyMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8088/companyA"></property>
</bean>
<bean id="professionClientA" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.professionMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8088/professionA"></property>
</bean>
<bean id="accountClientA" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.accountMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8088/accountA"></property>
</bean>
<!--============== clien ===========================-->
<!-- 客户端B -->
<bean id="HelloWorldClientB" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.RMI.HelloWorld"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8887/helloB"></property>
</bean>
<bean id="StudentClientB" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.studentMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8087/studentB"></property>
</bean>
<bean id="companyClientB" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.companyMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8087/companyB"></property>
</bean>
<bean id="professionClientB" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.professionMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8087/professionB"></property>
</bean>
<bean id="accountClientB" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceInterface" value="com.ptteng.dao.accountMapper"></property>
<property name="serviceUrl" value="rmi://127.0.0.1:8087/accountB"></property>
</bean>
</beans>
尝试启动其中一个服务
public class SpringServer {
public static void main(String[] args) {
ApplicationContext applicationContext= new ClassPathXmlApplicationContext("spring/SpringServerA.xml");
System.out.println("服务伴随spring服务启动");
}
}
请求测试
public class TestController {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/SpringClient.xml");
HelloWorld helloWord = (HelloWorld)applicationContext.getBean("HelloWorldClientA");
System.out.println(helloWord.helloWorld());
System.out.println(helloWord.sayHelloToSomeBody("去问问去恶趣味"));
}
}
还是有问题
中间出现的问题 :
下图红框处是service接口 不是数据库的mapper接口
不然就会错误
明天计划的事情:
解决bug 整合完controller的数据库查询
评论