zoukankan      html  css  js  c++  java
  • spring配置jax-ws

    在spring配置文件中新建bean(或者是在配置文件中添加bean),在该bean中添加指定的访问地址。

        @Bean
        public static SimpleJaxWsServiceExporter getSimpleJaxWsServiceExporter(){
            SimpleJaxWsServiceExporter wsServiceExporter = new SimpleJaxWsServiceExporter();
            wsServiceExporter.setBaseAddress("http://localhost:8088/sgyws");
            return wsServiceExporter;
        }

    然后新建一个接口

    @WebService
    public interface SgyWs {
    
        @WebMethod
        public String sayHi(); 
    }

    再有一个实现类,该类上的注解serviceName为ws的服务名,endpointInterface为接口地址。

    @WebService(serviceName="/sgyService",endpointInterface="com.btw.sgy.webService.SgyWs")
    //@SOAPBinding(style=Style.RPC)
    @Component
    public class SgyWsImpl implements SgyWs{
    
        @Override
        public String sayHi(){
            System.out.print("hi");
        };
    }

    最后启动服务即可,访问地址为http://localhost:8088/sgyws/sgyService。

    如果在第一步中,不加"/",则访问地址会变为http://localhost:8088/sgywssgyService。

    在jax-ws中,有两种重要的annotation:

    • @WebService
    • @WebMethod

    @WebService:标识某个类,或某个接口,为webService接口。

      有六个参数可以配置:

    1. endpointInterface:指向一个定义此WebService抽象定义接口的完整类路径
    2. name:WebService名;默认的port名为"实现类名+Port",binding名为"实现类名+PortBinding",通过指定name的值来替换 实现类名。
    3. portName:指定port名,可以完成替换默认port名,或由上面的"name"指定的port名。
    4. targetNamespace:指定targetNamespace值,默认的值为 "http://包名/",可以通过此变量指定一个自定义的targetNamespace值。(注:如果分别定义接口和实现,则他们有各自的targetNamespace)
    5. serviceName:指定service名
    6. wsdlLocation:指向一个预定义的wsdl的文件,替代自动生成的wsdl文件。

    @WebMethod:标注方法为webservice方法(可以省略)。

      有三个参数可以配置:

    1. action:指定此方法对应的action
    2. exclude:true --表示此方法包含在web服务中;false表示排除此方法
    3. operationName:指定方法对应的operation的名字。
  • 相关阅读:
    Myeclipse运行报错:an out of memory error has occurred的解决方法
    关于UnsupportedClassVersionError的错误处理
    Java设置session超时(失效)的三种方式
    mybatis自增长插入id
    揭开Java IO流中的flush()的神秘面纱
    mybatis多表查询
    在Myeclipse中提交代码到GitHub中
    一台电脑安装多个版本的jdk
    使用Git的Push出现rejected
    暴力解决HTMLTestRunner出现dict() ->new empty dictionary的问题
  • 原文地址:https://www.cnblogs.com/yxth/p/8425995.html
Copyright © 2011-2022 走看看