<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:property-placeholder location="classpath:client-config.properties"/>
<!-- 配置服务发现组件 -->
<bean id="serviceDiscovery" class="me.anduo.rpc.client.ServiceDiscovery">
<constructor-arg name="registryAddress" value="${registry.address}"/>
</bean>
<!-- 配置 RPC 代理 -->
<bean id="rpcProxy" class="me.anduo.rpc.client.RpcProxy">
<constructor-arg name="serviceDiscovery" ref="serviceDiscovery"/>
</bean>
</beans>
public class HelloServiceTest {
private RpcProxy rpcProxy;
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring-client.xml");
HelloServiceTest test = new HelloServiceTest();
test.rpcProxy = ctx.getBean(RpcProxy.class);
test.helloTest();
}
private void helloTest() {
try {
HelloService helloService = rpcProxy.create(HelloService.class);
String result = helloService.hello("World");
System.out.println(result);
//Assert.assertEquals("Hello! World", result);
} catch (Exception e) {
e.printStackTrace();
}
}
}