【问题标题】:Starting an axis2 service programmatically以编程方式启动axis2服务
【发布时间】:2009-09-29 09:13:38
【问题描述】:

我正在以编程方式在 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(),这会立即启动服务。但是,当第一个请求进来时,会创建另一个服务实例,所以这也不好。

【问题讨论】:

  • 用这种方法可以使用service.xml来配置服务吗?

标签: java web-services axis2


【解决方案1】:

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

【讨论】:

  • 是的,那太俗气了 :) 假设没有其他选项出现,我会这样做。
【解决方案2】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-03
    • 2018-10-07
    • 2018-10-14
    • 1970-01-01
    • 2019-07-15
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    相关资源
    最近更新 更多