2012-07-16 89 views
1

我已經使用了這個搜索引擎,但沒有運氣。我只想看看如何在嵌入式jetty中加載所需的所有服務以便能夠在JUnit中進行測試的示例。所以,我的目標就是這樣。如何在測試中加載spring HTTPInvoker到碼頭?

 

private String url = "SERVICE_URL"; 

@Before 
public void before() { 
    // start jetty with all the services I need 
} 

@Test 
public void shouldDoSthIWant() { 
    // invoke SERVICE_URL and test. 
} 
 

回答

1

發現這裏的示例應用程序演示瞭如何在一個簡單的Java應用程序中使用嵌入式碼頭運行HttpInvoker。你應該能夠適應這些代碼,以使它在一個合適的環境中工作。
http://code.google.com/p/jianwikis/wiki/SpringHttpRemotingWithEmbeddedJettyServer

再現來自該代碼/配置的相關章節削減到這裏

Server server = new Server(); 
SelectChannelConnector connector = new SelectChannelConnector(); 
connector.setPort(port); 

Context context = new Context(server, "/", Context.SESSIONS); 

DispatcherServlet dispatcherServlet = new DispatcherServlet(); 
dispatcherServlet.setContextConfigLocation("classpath:com/mycompany/config/DefaultServlet-servlet.xml"); 

ServletHolder servletHolder = new ServletHolder(dispatcherServlet); 
context.addServlet(servletHolder, "/*") 

DefaultServlet-servlet.xml中

<!-- This default handler takes care of each of the services enumerated below --> 
<bean id="defaultHandlerMapping" 
    class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> 

<bean id="helloService" class="com.mycompany.service.impl.HelloServiceImpl"/> 

<!-- SpringHTTP Service Exposure --> 

<bean name="/HelloService" 
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" 
    lazy-init="true"> 
    <property name="service" ref="helloService" /> 
    <property name="serviceInterface" 
      value="com.mycompany.service.iface.HelloService" /> 
</bean> 
相關問題