【发布时间】:2015-03-02 06:49:11
【问题描述】:
我有 2 个 JVM。
JettyJVM 运行 http 请求并具有使用 RmiProxyFactoryBean 支持到在 CoreJVM 中运行的 CarFacadeImpl 的接口 CarFacade
<bean class="org.springframework.remoting.rmi.RmiProxyFactoryBeanFactory">
<property name="serviceInterface" value="org.foo.CarFacade"/>
<property name="serviceUrl" value="rmi://#{HOST}:1099/CarFacade"/>
</bean>
核心JVM 在 Spring 容器中运行核心业务逻辑并具有 CarFacadeImpl
<bean id="carFacade" class="org.foo.impl.CarFacadeImpl"></bean>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="carFacade"></property>
<property name="serviceInterface" value="org.foo.CarFacade"></property>
<property name="serviceName" value="CarFacade"></property>
<property name="replaceExistingBinding" value="true"></property>
<property name="registryPort" value="1099"></property>
</bean>
此设置目前适用于 flex/blazds,并且我的服务可以很好地公开。
有什么方法我也可以通过 Jersey 公开这个吗?
我尝试使用 Impl 上的注释(首选),但组件扫描没有找到注释(显然因为接口没有它们) 所以我尝试使用接口上的注释,但球衣说它无法实例化接口。
// CarFacadeImpl.java - when I had the annotations on the class in the CoreJVM
@Path("car")
public class CarFacadeImpl implements CarFacade {
@GET
public String getName() {
return "CarFacade";
}
}
// CarFacade.java - When I had the annotations on the interface in JettyJVM
@Path("car")
public class CarFacade {
@GET
String getName();
}
我真的很想不必为了通过 rest 公开而编写额外的层。
我已经尝试过http://www.webappsolution.com/wordpress/2012/03/23/one-java-service-pojo-for-amfxmljson-with-spring-blazeds-jersey-jax-rs/ 此处的示例,它们之间无需 RMI 调用即可工作。
【问题讨论】:
-
您好!你用什么作为编组器?无论如何,我认为无论您使用什么,都需要在 JettyJVM 中实现该类(最后,您想获得一个对象!)。如果你使用例如gson 你不需要添加 getter 和 setter,只需要一个构造函数。在其他一些例如你至少需要二传手和二传手。
-
@lrnzcig 我们只是使用Jersey 的默认JSON 编组器用
@XmlRootElement注释类肯定有使用RmiProxyFactoryBean 的方法吗?我不介意是否需要对 Jersey 实施扩展。
标签: spring rest jersey jax-rs rmi