2009-09-29 3 views
3

내가 프로그래밍 축 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(); 

서비스에만 생성, 설정 - 방법 축을 강제로 서비스를 즉시 구성 할 수 있습니까?

업데이트 : cfg.addService()가 아닌 deployService()를 사용해 보았습니다. 그러면 즉시 서비스가 시작됩니다. 그러나 첫 번째 요청이 들어올 때 서비스의 또 다른 인스턴스가 만들어 지므로 좋지 않습니다.

+0

이 방법을 사용하면 service.xml을 사용하여 서비스를 구성 할 수 있습니까? –

답변

1

서비스를 시작하자마자 바로 코드를 호출하는 것이 좋습니다.

+0

그래, 그건 치즈 냄새가 될거야 :) 다른 옵션이 없다고 가정 할 때, 나는 그렇게 할 것입니다. – Andy

1

서비스 중 하나가 org.apache.axis2.engine.ServiceLifeCycle을 구현하도록 할 수 있습니다. 당신이 또한 com.example.MyService 클래스 구현 ServiceLifeCycle을하다

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

처럼 services.xml의 구성에서 그 발표해야 할 것 같다. 이 클래스는 일반적으로 컨테이너를 시작할 때 발생하는 서비스 배포에 대한 알림을받습니다. 다른 서비스 (프로그래밍 방식으로)를 시작하기 위해 코드를 연결할 수 있습니다.