您的位置:首页 > 编程语言 > Java开发

spring-hessian代理、服务那点事

2015-08-27 10:11 429 查看
暴露服务:

@SuppressWarnings("rawtypes")
private <a target=_blank href="eclipse-open:%E2%98%82=api/C:%5C/Users%5C/Administrator%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/org.springframework%5C/spring-web%5C/3.2.8.RELEASE%5C/799ae0503da5a9f980fecd38c9e6b23a71a406c8%5C/spring-web-3.2.8.RELEASE.jar%3Corg.springframework.remoting.caucho(HessianServiceExporter.class%E2%98%83HessianServiceExporter"><img style="BORDER-BOTTOM: medium none; POSITION: absolute; BORDER-LEFT: medium none; WIDTH: 16px; HEIGHT: 16px; BORDER-TOP: medium none; BORDER-RIGHT: medium none; LEFT: -21px" alt="Open Declaration" src="file:/D:/qby/src/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png" /> </a><a target=_blank class="header" href="eclipse-javadoc:%E2%98%82=api/C:%5C/Users%5C/Administrator%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/org.springframework%5C/spring-web%5C/3.2.8.RELEASE%5C/799ae0503da5a9f980fecd38c9e6b23a71a406c8%5C/spring-web-3.2.8.RELEASE.jar%3Corg">org</a>.<a target=_blank class="header" href="eclipse-javadoc:%E2%98%82=api/C:%5C/Users%5C/Administrator%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/org.springframework%5C/spring-web%5C/3.2.8.RELEASE%5C/799ae0503da5a9f980fecd38c9e6b23a71a406c8%5C/spring-web-3.2.8.RELEASE.jar%3Corg.springframework">springframework</a>.<a target=_blank class="header" href="eclipse-javadoc:%E2%98%82=api/C:%5C/Users%5C/Administrator%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/org.springframework%5C/spring-web%5C/3.2.8.RELEASE%5C/799ae0503da5a9f980fecd38c9e6b23a71a406c8%5C/spring-web-3.2.8.RELEASE.jar%3Corg.springframework.remoting">remoting</a>.<a target=_blank class="header" href="eclipse-javadoc:%E2%98%82=api/C:%5C/Users%5C/Administrator%5C/.gradle%5C/caches%5C/modules-2%5C/files-2.1%5C/org.springframework%5C/spring-web%5C/3.2.8.RELEASE%5C/799ae0503da5a9f980fecd38c9e6b23a71a406c8%5C/spring-web-3.2.8.RELEASE.jar%3Corg.springframework.remoting.caucho">caucho</a>.HessianServiceExporter buildHessianServiceExporter(
Class serviceInterface, Object service) {
HessianServiceExporter HessianServiceExporter = new HessianServiceExporter();
HessianServiceExporter.setServiceInterface(serviceInterface);
HessianServiceExporter.setService(service);
return HessianServiceExporter;
}
@Bean(name = "/helloService ")
public HessianServiceExporter helloServiceExporter() {
return buildHessianServiceExporter(HelloService .class, helloService );
}
@Autowired
private HelloService helloService ;


spring-代理hessian-bean

@Bean
public HessianProxyFactoryBean helloService() {
return buildHessianProxyFactoryBean(HelloService.class, "helloService");
}

@SuppressWarnings("rawtypes")
private HessianProxyFactoryBean buildHessianProxyFactoryBean(
Class serviceInterface, String serviceName) {
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceInterface(serviceInterface);
factory.setServiceUrl(hessianSererUrl + "/remoting/xxx/"
+ serviceName);
return factory;
}


纯java代码代理:

public static void main(String[] args) throws Exception {

HessianProxyFactory factory = new HessianProxyFactory();
xxxxx hello = (xxxxxx) factory.create(
MgtResourceService.class,
"http://localhost:12080/remoting/xxx/xxxxxx");

System.out.println(hello.findAll());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java hessian spring