• 利用spring、cxf编写并发布webservice


    配置文件spring-wsServer.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:context
    ="http://www.springframework.org/schema/context"
      xmlns:jaxws
    ="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <!-- 需要注意两个地方,将CXF所需的配置文件import到Spring容器中,但所需的3个配置文件并不在工程里,而是在Spring容器初始化时自动创建,这里需要显示的将其import进来; 定义了一个Webservice的端点,其中id是其存放在Spring容器中的标识, implementor用于标注实现类, address提供服务的地址. --> <!-- Import Apache CXF Bean Definition --> <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"/> <bean id="wsCodeServiceImpl" class="com.cbt.webservice.impl.WsCodeServiceImpl"/> <!-- 通过Spring创建数据绑定的类--> <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" /> <bean id="jaxWsServiceFactoryBean" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"> <property name="wrapped" value="true" /> <property name="dataBinding" ref="aegisBean" /> </bean> <jaxws:endpoint id="wsCodeService" implementor="#wsCodeServiceImpl" address="/codeWebService" > <jaxws:serviceFactory> <ref bean="jaxWsServiceFactoryBean" /> </jaxws:serviceFactory> </jaxws:endpoint> </beans>

    web.xml

     <!-- Apache CXFServlet -->
        <servlet>
            <servlet-name>CXFServlet</servlet-name>
            <servlet-class>
                org.apache.cxf.transport.servlet.CXFServlet
            </servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <!-- CXFServlet Mapping -->
        <servlet-mapping>
            <servlet-name>CXFServlet</servlet-name>
            <url-pattern>/ws/*</url-pattern>
        </servlet-mapping>

    java代码

      接口

    package com.cbt.webservice;
    
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    
    
    @WebService
    public interface WsCodeService {
    	
    	@WebResult(name="code")
    	public String getCodeByPrefix(@WebParam(name="codePrefix")String codePrefix);
    }
    

      接口实现类

    package com.cbt.webservice.impl;
    
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    import com.cbt.service.system.CodeService;
    import com.cbt.webservice.WsCodeService;
    
    @WebService
    public class WsCodeServiceImpl implements WsCodeService {
    	
    	@WebResult(name="code")
    	public String getCodeByPrefix(@WebParam(name="codePrefix")String codePrefix) {
    		//写你的实现功能的代码
    	}
    
    }
    

      启动项目后浏览器访问 http://localhost:8080/spm/ws/codeWebService
      说明:spm为你的项目名  ws为你在web.xml中配置的访问路径   codeWebService为你在配置文件中jaxwa:endpoint中的address

    若出现类似下图,则发布成功

    
    
    
  • 相关阅读:
    Spring事务管理
    Java GC算法
    内连接,左连接,右连接
    ThreadLocal相关
    @Autowired 与 @Resource的区别
    spring注解
    BZOJ 1040 ZJOI 2008 骑士 树形DP
    HDU 5575 Discover Water Tank 并查集 树形DP
    BZOJ 3571 画框 KM算法 最小乘积最大权匹配
    ZOJ 3256 Tour in the Castle 插头DP 矩阵乘法
  • 原文地址:https://www.cnblogs.com/wangxufeng/p/4517407.html
Copyright © 2020-2023  润新知