그냥 사는 이야기

Axis Web Service의 server side 구현 시 spring context 가져오는 법 본문

Development/Web

Axis Web Service의 server side 구현 시 spring context 가져오는 법

없다캐라 2013. 4. 19. 11:28
반응형

Axis Web Service의 server side 구현 시 spring context 가져오는 법

이 문제 가지고 한동안 맘고생 많이 했다. 스프링도 잘 모르고 웹서비스도 잘 모르는데 억지로 물어물어 구현해놨더니 사실 따로 놀고 있었다. 스프링 프레임웍으로 한개의 인스턴스가 돌고 있고 axis server side로 외부에 웹서비스를 열어놓았는데 외부에서 web service를 호출하면 context가 전혀 달라 별도로 돌아가고 있었다.

웹서비스 호출 메소드는 스프링의 bean 들을 참조해야 하는데 모두 null 값이었다.

 

이걸 가능하게 하기 위해 처음에는 웹서비스 호출메소드에서

ApplicationContext context = new ClassPathXmlApplicationContext("/spring/context-*.xml");
GeneralDao generalDao = (GeneralDao) context.getBean("generalDao");
...

이런 식으로 해서 dao bean을 얻어온다고(?) 생각하면서 쓰고 있었는데 헐......... 그게 아니었다.

 

다행히 구글링을 통해서 방법을 알아보니 server-config.wsdd 에서 

...
 <ns1:handler name="ContextLoaderListener" type="org.springframework.web.context.ContextLoaderListener">
    <ns1:parameter name="contextConfigLocation" value="classpath:/spring/context-*.xml">
 </ns1:parameter></ns1:handler>
...

을 먼저 추가시켜 준 후 실제 코드에서는

WebApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
BeanFactory beanFactory = context;
GeneralDao generalDao = (GeneralDao) beanFactory.getBean("generalDao");

이런식으로 가져 오면 된다.

http://forum.springsource.org/showthread.php?104517-Spring-Context-In-Axis-Web-Service

Comments