2015-03-02 22 views
1

我有2個JVM的。如何在Impl遠程時註釋Jersey POJO?

JettyJVM 運行http請求,並且具有使用RmiProxyFactoryBean到CarFacadeImpl在CoreJVM運行備份

<bean class="org.springframework.remoting.rmi.RmiProxyFactoryBeanFactory"> 
    <property name="serviceInterface" value="org.foo.CarFacade"/> 
    <property name="serviceUrl" value="rmi://#{HOST}:1099/CarFacade"/> 
</bean> 

CoreJVM 運行在一個彈簧容器核心業務邏輯,並具有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> 
接口CarFacade

這個設置目前適用於flex/blazds,我的服務很好地顯示。

有沒有什麼辦法可以讓我通過澤西公開?

我嘗試使用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(); 
} 

我真的很想不必爲了通過休息來公開額外的圖層。

我試過了這裏的例子http://www.webappsolution.com/wordpress/2012/03/23/one-java-service-pojo-for-amfxmljson-with-spring-blazeds-jersey-jax-rs/,它們在沒有RMI調用的情況下工作。

+0

您好!你用什麼作爲編組?無論如何,我認爲無論你使用什麼,你都需要在你的JettyJVM中實現這個類(最後,你想獲得一個對象!)。如果你使用例如你不需要添加getters和setter,只是一個構造函數。在其他一些例如moxy你至少需要二傳手和二傳手。 – lrnzcig 2015-03-02 17:53:28

+0

@lrnzcig我們只是使用Jersey的默認JSON編組註釋類@@ XmlRootElement' 當然,必須有一種方法來使用RmiProxyFactoryBean?我不介意是否需要實施對澤西島的擴展。 – 2015-03-02 19:39:37

回答

0

我找到了答案,至少在澤西島2.16。它需要的註釋是在界面上,但這遠遠不是創建一個全新的層

改寫默認路徑掃描登記和註冊使用類似這樣更好的東西:

// Jersey ResourceConfig 
final ResourceConfig rc = new ResourceConfig(); 

// Get my Spring context 
final ApplicationContext context = new ClassPathXmlApplicationContext("clientContext.xml"); 
// Use Springs class path scanner to find @Path annotated classes 
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false) { 
    @Override 
    protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { 
     return beanDefinition.getMetadata().isIndependent(); 
    } 
}; 
scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class)); 

// For each class found in package (and sub packages) 
for (BeanDefinition bd : scanner.findCandidateComponents("example")) { 
    try { 
     // Get the class 
     Class clazz = HttpServer.class.getClassLoader().loadClass(bd.getBeanClassName()); 
     // Get the proxy 
     Object bean = context.getBean(clazz); 
     if (bean != null) { 
      // Register the proxy with the interface 
      rc.register(bean, clazz); 
     } 
    } catch (ClassNotFoundException e) { 
     e.printStackTrace(); 
    } 
}