我们在使用cxf的时候一般都会集成spring,下面看下具体的配置方式和程序代码实现。
spring 配置:
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” />
<import resource=”classpath:META-INF/cxf/cxf-extension-jaxws.xml”/>
<bean id=”cxfTT” class=”com.hxy.services.CxfInterFaceImp” />
<jaxws:endpoint id=”cxfInterFace” implementor=”#cxfTT” address=”/CxfInterFace” publishedEndpointUrl=”http://127.0.0.1:2011/CxfTest/services/CxfInterFace”/>
web.xml 配置
Xml代码.
<web-app>
<!– spring配置 –>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-cxf.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-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>
</web-app>
Java代码.
package com.hxy.services;
import javax.jws.WebService;
@WebService
public interface CxfInterface {
public String queryMe(String sql);
}
Java代码.
package com.hxy.services;
import javax.jws.WebService;
@WebService(endpointInterface = “com.hxy.services.CxfInterface”)
public class CxfInterFaceImp implements CxfInterFace {
public String queryMe(String sql) {
return “返回sql:::”+sql;
}
}
简单的服务端接口生成完成.启动服务 http://127.0.0.1:8080/CXFServer/services/CxfInterface?wsdl
转载请注明来源网站:blog.ytso.com谢谢!
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/7028.html