Announcement Announcement Module
Collapse
No announcement yet.
Spring Context In Axis Web Service Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Context In Axis Web Service

    So let me start out by saying I have searched the forum and Google for the answer to the question with no luck so far. I'm new to Spring so it's quite possible (and likely) I'm making a rookie mistake. Now onto my question:

    I have an existing SOAP web service that I wrote using Eclipse, Axis, and Tomcat. Basically I designed my WSDL file and generated the service skeleton from that WSDL file. I have since discovered Spring because I want to be able to switch between Databases by simply changing a configuration file. I've been able to write a stand-alone Spring application where I can configure the DAO, no problem. Now what I am attempting to do is incorporate that configurability into my web service. So far the only way I've been able to do this is to brute force move the applicationContext.xml file into WEB-INF/classes after deployment in combination with the following code in my Skeleton object.
    Code:
     public MySOAPSkeleton() {
            
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
            BeanFactory beanFactory = applicationContext;
            impl = (MyBean) beanFactory.getBean("myBean");
    
        }
    Obviously this is not ideal. Googling lead me to the ServletEndpointSupport solution which is now deprecated. I've also seen suggestions to use RmiServiceExporter which is probably the way to go but I don't know how to integrate that with Tomcat.

    So simply put I'm looking for information on how best to get Spring beans into my web service without having to fundamentally change my web service. This is not a servlet so I cannot use the ServletContext object.

  • #2
    So it appears I've stumbled upon a solution myself. Hopefully posting it here will help someone else or someone will yell at me and tell my why it's wrong to do it this way.

    In my server-config.wsdd I added the following lines:

    Code:
     <ns1:handler name="ContextLoaderListener" type="org.springframework.web.context.ContextLoaderListener" >
        <ns1:parameter name="contextConfigLocation" value="WEB-INF/applicationContext.xml"/>
     </ns1:handler>
    Then in my SOAPSkeleton class I have the following:

    Code:
    public MySOAPSkeleton() {
            org.springframework.web.context.WebApplicationContext context = org.springframework.web.context.ContextLoaderListener.getCurrentWebApplicationContext();
            BeanFactory beanFactory = context;
            impl = (MyBean) beanFactory.getBean("myBean");
        }
    This appears to do what I want.

    Comment

    Working...
    X