Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在测试中将SpringHttpInvoker加载到jetty?_Java_Spring_Testing_Junit_Embedded Jetty - Fatal编程技术网

Java 如何在测试中将SpringHttpInvoker加载到jetty?

Java 如何在测试中将SpringHttpInvoker加载到jetty?,java,spring,testing,junit,embedded-jetty,Java,Spring,Testing,Junit,Embedded Jetty,我在谷歌上搜索过这个,但运气不好。我只是想看看如何在嵌入式jetty中加载我需要的所有服务,以便能够在JUnit中进行测试。所以,我的目标是这样的 private String url = "SERVICE_URL"; @Before public void before() { // start jetty with all the services I need } @Test public void shouldDoSthIWant() { // invoke SERVI

我在谷歌上搜索过这个,但运气不好。我只是想看看如何在嵌入式jetty中加载我需要的所有服务,以便能够在JUnit中进行测试。所以,我的目标是这样的


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.
}

这里的示例应用程序展示了如何在一个简单的java应用程序中使用嵌入式jetty运行HttpInvoker。您应该能够调整该代码,使其在junit中工作。

从下面的pare复制代码/配置的相关部分

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>

这里的示例应用程序展示了如何在一个简单的java应用程序中使用嵌入式jetty运行HttpInvoker。您应该能够调整该代码,使其在junit中工作。

从下面的pare复制代码/配置的相关部分

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>