cxf实现webservice接口的配置

1、web.xml配置
<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>


2、接口配置
<!-- apache cxf 与 spring -->
	<jaxws:server id="exchangeMessage" serviceClass="com.gd.service.IExchangeMessage" address="/ExchangeMessage">
		<jaxws:serviceBean>
		  	<bean class="com.gd.service.impl.ExchangeMessageImpl">
				<property name="baseDAO"  ref="BaseDAO"/>
		  	</bean>
		</jaxws:serviceBean>
	</jaxws:server>

接口类
@WebService(name="ExchangeMessage")
public interface IExchangeMessage {

	@WebMethod
	public String exchange(@WebParam(name="xmlStr")String xmlStr);
	
	public String saveXmlFile(String xmlStr);
}

实现类
@WebService(name="ExchangeMessage")
public class ExchangeMessageImpl implements IExchangeMessage {
	private BaseDAO baseDAO;
	public void setBaseDAO(BaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	
	@WebMethod
	public String exchange(@WebParam(name = "xmlStr") String xmlStr) {
		
		return xxx;
	}


这是一个简单的实现,具体复杂的请参照API等。
调用举例:
http://localhost:8080/TMRemoteEdu/services/ExchangeMessage/exchange?xmlStr=XXX

你可能感兴趣的:(java,apache,webservice)