Axis2 + spring integration, axis2spring

Source: Internet
Author: User

Axis2 + spring integration, axis2spring
Reposted from: http://www.cnblogs.com/linjiqin/archive/2011/07/05/2098316.html1、create a new web project. The final project directory is as follows:

Note: This article only focuses on webservice server development, so com. ljq. client and com. ljq. test are ignored

2. Add the required jar

3. HelloWorld

package com.ljq.service;

public interface HelloWorld {
public String greeting(String name);
public String print();
}

4. Interface implementation class HelloWorldBean

Package com. ljq. service;

Public class HelloWorldBean implements HelloWorld {
Public String greeting (String name ){
Return "hello" + name;
}

Public String print (){
Return "My name is Lin ji qin ";
}
}

5. webservice HelloWorldWebService

Package com. ljq. service;

Import org. apache. axis2.AxisFault;
Import org. apache. axis2.ServiceObjectSupplier;
Import org. apache. axis2.description. AxisService;
Import org. apache. axis2.description. Parameter;
Import org. apache. axis2.i18n. Messages;
Import org. springframework. beans. BeansException;
Import org. springframework. context. ApplicationContext;
Import org. springframework. context. ApplicationContextAware;

/**
* Axis2 spring bean not found or Spring applicationContext not found may appear.
*
* Solution: build your own ServiceObjectSupplier, implement the ServiceObjectSupplier interface, and also implement the Spring ApplicationContextAware interface.
*
*
* @ Author Administrator
*
*/
Public class HelloWorldWebService implements ServiceObjectSupplier,
ApplicationContextAware {
Private static ApplicationContext ctx;

Public Object getServiceObject (AxisService axisService) throws AxisFault {
Parameter springBeanName = axisService. getParameter ("SpringBeanName ");
String beanName = (String) springBeanName. getValue (). trim ();
If (beanName! = Null ){
If (ctx = null)
Throw new AxisFault ("applicationContext is NULL! ");
If (ctx. getBean (beanName) = null)
Throw new AxisFault ("Axis2 Can't find Spring Bean:" + beanName );
Return ctx. getBean (beanName );
} Else {
Throw new AxisFault (Messages. getMessage ("paramIsNotSpecified ",
"SERVICE_SPRING_BEANNAME "));
}

}

Public void setApplicationContext (ApplicationContext ctx)
Throws BeansException {
This. ctx = ctx;
}

}

6. Configure the web. xml file

<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd>
<! -- Add a spring listener -->
<Listener>
<Listener-class>
Org. springframework. web. context. ContextLoaderListener
</Listener-class>
</Listener>
<! -- Load the spring configuration file -->
<Context-param>
<Param-name> contextConfigLocation </param-name>
<Param-value>/WEB-INF/applicationContext. xml </param-value>
</Context-param>


<! -- Register the servlet of axis2 -->
<Servlet>
<Servlet-name> AxisServlet </servlet-name>
<Servlet-class>
Org. apache. axis2.transport. http. AxisServlet
</Servlet-class>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-name> AxisServlet </servlet-name>
<Url-pattern>/services/* </url-pattern>
</Servlet-mapping>


<Welcome-file-list>
<Welcome-file> index. jsp </welcome-file>
</Welcome-file-list>
</Web-app>

7. Configure applicationContext. xml in the WEB-INF directory (created by yourself if it does not exist)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="applicationContext"
class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
<bean id="helloWorld" class="com.ljq.service.HelloWorldBean"></bean>
</beans>

8. Configure services. xml in the WEB-INF \ services \ axis \ META-INF \ directory (created by yourself if not present)

<? Xml version = "1.0" encoding = "UTF-8"?>
<Service name = "hwWebService">
<Description> integration of axis2 and spring </description>
<! -- Use the ServiceObjectSupplier parameter to specify the SpringServletContextObjectSupplier class to obtain the Spring ApplicationContext object -->
<Parameter name = "ServiceObjectSupplier">
Org. apache. axis2.extensions. spring. receivers. SpringAppContextAwareObjectSupplier
</Parameter>
<! --
SpringBeanName cannot be changed
HelloWorld is the implementation class id registered in spring.
-->
<Parameter name = "SpringBeanName"> helloWorld </parameter>
<! --
The <messageReceivers> element is used to set the processor used to process WebService methods.
For example, the getGreeting method has a return value. Therefore, you must use the RPCMessageReceiver class that can process input and output,
The update method does not return values. Therefore, you must use the RPCInOnlyMessageReceiver class that can only process the input.
-->
<MessageReceivers>
<MessageReceiver mep = "http://www.w3.org/2004/08/wsdl/in-only"
Class = "org. apache. axis2.rpc. receivers. RPCInOnlyMessageReceiver"/>
<MessageReceiver mep = "http://www.w3.org/2004/08/wsdl/in-out"
Class = "org. apache. axis2.rpc. receivers. RPCMessageReceiver"/>
</MessageReceivers>
</Service>

The integration of axis2 and spring has been developed. Next, deploy the project to tomcat,

Then http: // localhost: 8083/axis2spring/services/hwWebService? Wsdl access


This error has recently occurred in the integration of axis2 141 and spring by instance.

It seems that there is no repair

Why can't axis2 + spring release specified methods but all methods in the entire service class?

It is said that this is a bug in axis2. Is this fixed in the latest version? How can this problem be solved? Problem added: It seems that the problem occurred after adding spring transactions does not seem to be fixed.
 

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.