public interface HelloService {
String greet(String name);
}
@Service
public class HelloServiceImpl implements HelloService {
@Override
public String greet(String name) {
return "Hello, " + name + "!";
}
}
<bean id="helloService" class="com.example.HelloServiceImpl" />
<http-invoker:exporter service-interface="com.example.HelloService"
service-ref="helloService"
path="/hello" />
@Configuration
public class AppConfig {
@Bean
public HelloService helloService() {
HttpInvokerProxyFactoryBean proxyFactoryBean = new HttpInvokerProxyFactoryBean();
proxyFactoryBean.setServiceUrl("http://localhost:8080/hello");
proxyFactoryBean.setServiceInterface(HelloService.class);
proxyFactoryBean.afterPropertiesSet();
return (HelloService) proxyFactoryBean.getObject();
}
}
@Component
public class HelloClient {
@Autowired
private HelloService helloService;
public String getGreeting(String name) {
return helloService.greet(name);
}
}