3

我以编程方式在 Axis 2 (1.5) 中启动服务,如下所示:

ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);

AxisConfiguration cfg = context.getAxisConfiguration();
Map<String, MessageReceiver> mrMap = new HashMap<String, MessageReceiver>();
mrMap.put("http://www.w3.org/ns/wsdl/in-only", RPCInOnlyMessageReceiver.class.newInstance());
mrMap.put("http://www.w3.org/ns/wsdl/in-out", RPCMessageReceiver.class.newInstance());

AxisService service = AxisService.createService(MonitorWebService.class.getName(), cfg, mrMap, "", "http://samples", MonitorWebService.class.getClassLoader());
service.setScope("application");
cfg.addService(service);
SimpleHTTPServer server = new SimpleHTTPServer(context, 8080);
server.start();

使用此设置,服务仅在第一个操作请求到达时创建 - 如何强制轴立即构建服务?

更新:我尝试使用 deployService(),而不是 cfg.addService(),这会立即启动服务。但是,当第一个请求进来时,会创建另一个服务实例,所以这也不好。

4

2 回答 2

1

一种俗气的方法是让代码在您启动服务后立即调用服务。

于 2009-09-29T18:46:55.393 回答
1

您可以让您的一项服务实现 org.apache.axis2.engine.ServiceLifeCycle。看来您还需要在 services.xml 配置中声明,就像这样

<service name="MyService" scope="application" class="com.example.MyService">
...
</service>

其中 com.example.MyService 是实现 ServiceLifeCycle 的类。此类将在服务部署时收到通知,这通常发生在容器启动时。您可以挂钩您的代码以在那里(以编程方式)启动其他服务。

于 2011-08-20T11:09:32.240 回答