cxf框架webService接口服务端详细配置

Spring和cxf整合,Service.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://cxf.apache.org/jaxws
            http://cxf.apache.org/schemas/jaxws.xsd
            http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">  
   

    <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" />


    <!-- webService发布地址 , #userServiceImpl引用bean方式,也可以写成类的全路径 -->
    <!--userServiceImpl 加入数据连接, 在此引用 -->
    <jaxws:endpoint id="receiveService"  implementorClass="com.htxx.service.ReceiveServiceI"
     implementor="#receiveServiceImpl" address="/ReceiveServiceI">
        <!--inInterceptors表示被外部调用时,调用此拦截器 -->
        <jaxws:inInterceptors>            
            <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
        </jaxws:inInterceptors>
    </jaxws:endpoint>
    <jaxws:endpoint id="HelloServiceI"  implementorClass="com.htxx.service.HelloServiceI"-----服务接口
 服务接口实现类名称-------implementor="#HelloServiceImpl" address="/HelloServiceI">------指的是客户端访问你的服务地址,为的是不暴露本地地址

        <!--inInterceptors表示被外部调用时,调用此拦截器 -->
        <jaxws:inInterceptors>            
            <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
        </jaxws:inInterceptors>
    </jaxws:endpoint>
    
</beans>


web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name></display-name>
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>fpjk.root</param-value>
    </context-param>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>
    <context-param>
        <param-name>log4jRefreshInterval</param-name>
        <param-value>6000</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

<!-- Spring 刷新Introspector防止内存泄露 -->

<listener>

<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

</listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:beans.xml,WEB-INF/services.xml</param-value>
    </context-param>
    <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>/CXF/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>openSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
        <init-param>
            <param-name>singleSession</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>openSessionInViewFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
    <welcome-file>/jsp/xtxx/yhxx/login.jsp</welcome-file>
  </welcome-file-list>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>

实现类

package com.htxx.service.impl;

import java.util.Iterator;

import javax.annotation.Resource;
import javax.jws.WebService;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

@Service
@Scope("prototype")
@WebService(targetNamespace = "com.htxx.service", endpointInterface = "com.htxx.service.HelloServiceI")
public class HelloServiceImpl implements HelloServiceI {

    private static final Logger log = LogManager.getLogger(HelloServiceImpl.class);

                                                  //实现方法
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我了解了您的问题。使用Spring Boot和CXF框架搭建一个Webservice服务端的步骤如下: 1. 首先,在您的项目中添加CXF和Spring Boot的依赖,例如: ``` <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.3.6</version> </dependency> ``` 注意,这里使用的是CXF的JAX-WS模块,您也可以根据需要选择其他模块。 2. 接着,在您的配置文件中添加CXF配置,例如: ``` @Configuration public class CxfConfig { @Bean public ServletRegistrationBean<CXFServlet> cxfServlet() { return new ServletRegistrationBean<>(new CXFServlet(), "/yourWebserviceUrl/*"); } @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); } @Bean public YourWebService yourWebService() { return new YourWebService(); } @Bean public Endpoint yourWebServiceEndpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), yourWebService()); endpoint.publish("/YourWebServiceUrl"); return endpoint; } } ``` 这里配置CXF的Servlet,以及您自己实现的Webservice服务类和Endpoint。注意,您需要将 "/yourWebserviceUrl/" 和 "/YourWebServiceUrl" 替换为您自己的URL。 3. 最后,您可以实现您的Webservice服务类,例如: ``` @Service @WebService(serviceName = "YourWebService") public class YourWebService { @WebMethod public String hello(@WebParam(name = "name") String name) { return "Hello, " + name + "!"; } } ``` 这里实现了一个简单的hello方法,接收一个name参数并返回一个包含该参数的问候语。 完成以上步骤后,您就成功地搭建了一个基于CXF和Spring Boot的Webservice服务端。当您在浏览器中输入"http://localhost:8080/YourWebServiceUrl?wsdl"时,您将看到您的Webservice服务的WSDL文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值