简单的spring+CXF例子

包的引入
http://115.com/file/aq50utt5#
cxf.rar(31天的有效期)
配置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>


applicationContext.xml

        <import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
       <!-- hello -->
	<bean id="aegisBean"  
        class="org.apache.cxf.aegis.databinding.AegisDatabinding" /> 
          
    <bean id="jaxws-and-aegis-service-factory"  
        class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">   
        <property name="dataBinding" ref="aegisBean" />   
    </bean>  

   <!-- hello -->
  <jaxws:server id="hello" serviceClass="com.framework.webservice.Hello" address="/Hello">
  		<jaxws:serviceBean>
  			<bean class="com.framework.webservice.HelloImpl">
  			</bean>
  		</jaxws:serviceBean>
  </jaxws:server>



然后是我们的接口
package com.framework.webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface Hello {
	@WebMethod(operationName="SayHello")
	@WebResult(name = "result")
	public String sayHello(@WebParam(name = "s")String s);
}




实现类


package com.framework.webservice;

import javax.jws.WebService;

@WebService(endpointInterface = "com.framework.webservice.Hello")
public class HelloImpl implements Hello{
	public String  sayHello(String s) {
		System.out.println( "Insist on"+s);
		return "Insist on";
	}

}




然后启动服务

在浏览器中输入这里就输入我的:http://localhost:8080/framework/services/Hello?wsdl
得到


简单的spring+CXF例子_第1张图片


这个就算是成功访问到了

然后访问接口的方法:
http://localhost:8080/framework/services/Hello/SayHello?s=%E5%93%88%E5%93%88%E5%93%88%E5%93%88%E5%93%88%E5%93%88

SayHell为调用的方法s为参数

这里可以看到



然后访问
结果


简单的spring+CXF例子_第2张图片


OK。





你可能感兴趣的:(CXF,srping)