我有一个控制台应用程序,可以用以下代码简要描述:
public static void main(String[] args) throws InterruptedException {
JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
sfb.setResourceClasses(DummyService.class);
sfb.setResourceProvider(DummyService.class, new SingletonResourceProvider(new DummyServiceImpl()));
sfb.setProvider(new JacksonJaxbJsonProvider());
sfb.setAddress("http://0.0.0.0:9000/");
BindingFactoryManager manager = sfb.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory();
bindingFactory.setBus(sfb.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);
Server server = sfb.create();
server.stop(); // here
}
我从 Eclipse 运行这个程序,我希望它立即完成,因为我server.stop()
最终是正确的。这行代码是由应用程序执行的,所以我必须手动关闭它。这是 CXF 打印到控制台的日志:
Aug 13, 2012 10:51:10 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://0.0.0.0:9000/
2012-08-13 22:51:10.598:INFO:oejs.Server:jetty-7.5.3.v20111011
2012-08-13 22:51:10.646:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:9000 STARTING
2012-08-13 22:51:10.662:INFO:oejsh.ContextHandler:started o.e.j.s.h.ContextHandler{,null}
2012-08-13 22:51:10.663:INFO:oejsh.ContextHandler:stopped o.e.j.s.h.ContextHandler{,null}
在对应用程序的调用server.stop()
仍在运行后,但服务器没有响应任何请求,所以感觉我需要关闭其他东西。
什么是阻止它的正确方法?
更新
server.stop();
server.destroy();
也不行。
更新
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.6.1</version>
</dependency>