Axis2 integrates Spring in Web projects

Source: Internet
Author: User

Axis2 integrates Spring in Web projects

I. Description:

In the previous article, we talked about the integration process between Axis2 and Web projects. If we use the Spring framework in a Web project, how can we perform configuration operations related to Axis2?

Ii. Integration of Axis2 and Spring

① Create the AxisSpringDemo project and add the Axis2 jar package related to Spring to it

Jar required by Spring:

 

aopalliance-1.0.jaraspectjrt.jaraspectjweaver.jarspring-aop-3.2.1.RELEASE.jarspring-beans-3.2.1.RELEASE.jarspring-context-3.2.1.RELEASE.jarspring-core-3.2.1.RELEASE.jarspring-expression-3.2.1.RELEASE.jarspring-tx-3.2.1.RELEASE.jarspring-web-3.2.1.RELEASE.jar
Jar required by Axis2:

 

 

activation-1.1.jaraxiom-api-1.2.15.jaraxiom-impl-1.2.15.jaraxis2-adb-1.6.4.jaraxis2-jaxws-1.6.4.jaraxis2-kernel-1.6.4.jaraxis2-spring-1.6.4.jaraxis2-transport-http-1.6.4.jaraxis2-transport-local-1.6.4.jaraxis2-xmlbeans-1.6.4.jarcommons-fileupload-1.3.1.jarcommons-httpclient-3.1.jarcommons-io-2.1.jarcommons-logging-1.1.1.jargeronimo-stax-api_1.0_spec-1.0.1.jarhttpcore-4.0.jarjsr311-api-1.1.1.jarmail-1.4.jarneethi-3.0.2.jarwoden-api-1.0M9.jarwsdl4j-1.6.2.jarxml-resolver-1.2.jarXmlSchema-1.4.7.jar

 

② Add Spring and Axis2 to the web. xml file of the Project to Support Configuration:

 

    
     
  
   contextConfigLocation
      
  
   classpath:applicationContext.xml
    
   
     
  
   org.springframework.web.context.ContextLoaderListener
    
        
         
  
   AxisServlet
          
  
   org.apache.axis2.transport.http.AxisServlet
          
  
   1
    
   
         
  
   AxisServlet
          
  
   /services/*
    
 

 

③ Same as the integration of web Project, the conf, axis2-web, modules folder to the AxisSpringDemo project under the corresponding location.

④ Create the com. elgin. spring. webservice package under src and create SpringWebServiceDemo class that provides WebService. The Code is as follows:

 

package com.elgin.spring.webservice;import java.util.Random;import org.springframework.stereotype.Component;@Component("springWebService")public class SpringWebServiceDemo {    public String springHello(){return "hello spring-axis2"; }public int getAge(){return new Random().nextInt(80);}public void update(){System.out.println("update something..");}}

 

⑤ Create a Spring configuration file in the class path: applicationContxt. xml configuration file

 

  
  
 
⑥ Configure the Axis2 WebService:

 

Create the following level directory under the WEB-INF of the AxisWebDemo project: services/springServices/META-INF/services. xml

Services. xml configuration content:

 

      
          
   
    Web Service
                  
   
    springWebService
         
   
    org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
                   
                  
                   
            
        
    
  
Iii. Test summary:

 

After completing the preceding steps, complete the configuration and start the Tomcat loaded by the project. Access: http: // localhost: 8080/AxisSpringDemo/services/listServices on the following page:

Through the test above, we can find that:

After adding Spring, except for the introduction and configuration of spring, the only difference is that the configuration of services. xml has changed.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.