2009-09-29 25 views
3

我開始編程在軸2(1.5)服務,像這樣:開始的Axis2服務編程

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(),並立即啓動服務。我試過使用deployService()而不是cfg.addService()。但是,當第一個請求進入時,會創建另一個服務實例,所以這也不好。

+0

使用這種方法我可以使用service.xml來配置服務? – 2011-12-27 14:32:03

回答

1

一個俗氣的做法是讓代碼在啓動服務後立即調用服務。

+0

是的,這將是俗氣:)假設沒有其他選項出現,我會這樣做。 – Andy 2009-09-30 11:37:21

1

你可以讓你的一個服務實現org.apache.axis2.engine.ServiceLifeCycle。看來你還需要宣佈在services.xml的配置,這樣的

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

其中com.example.MyService是類實現ServiceLifeCycle。此類將通過服務部署進行通知,這通常在容器啓動時進行。您可以掛鉤您的代碼以在其中啓動其他服務(以編程方式)。