cxf http 代码自动生成

1.下载 cxf

直接进入镜像下载
http://mirrors.tuna.tsinghua.edu.cn/apache/cxf/3.1.12/apache-cxf-3.1.12.zip

2.配置 CXF 环境变量

CXF_HOME=E:/installFile/cxf/apache-cxf-3.1.12
在 CLASSPATH 后添加 %CXF_HOME%/lib;
在 Path 后添加 %CXF_HOME%/bin;
查看版本是否配置成功
wsdl2java -v

3.生成服务端代码

打开 cmd 进入 wsdl 所在目录执行

wsdl2java -server -impl -d E:\work\waikuai\pom\cxf\src\main\java HelloEsbService.wsdl

4.配置服务端

<?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"
    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">
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <jaxws:endpoint id="userService"
        implementor="com.midea.service.esbpro.abstraction.atomic.technology_helloesbservice.v1.HelloEsbServicePortImpl"
        address="/userWS">
    </jaxws:endpoint>

</beans>

5.POM.XML

<cxf.version>3.1.12</cxf.version>

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

6.web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>CXFService</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFService</servlet-name>
        <url-pattern>/cxf/*</url-pattern>
    </servlet-mapping>

</web-app>

7.启动测试 访问

http://localhost:8015/cxf/cxf/userWS?wsdl

8.客户端代码生成

cmd 进入客户端源码目录执行

wsdl2java -keep http://localhost:8015/cxf/cxf/userWS?wsdl

或者执行

wsdl2java -client -impl -d E:\work\waikuai\pom\cxf_client\src\main\java HelloEsbService.wsdl

9.打开生成的模拟客户端 _cliet 调用接口ok

这个client 没有集成 spring

10. 客户端 spring 配置

<bean id="client" class="com.midea.service.esbpro.abstraction.atomic.technology_helloesbservice.v1.HelloEsbService" factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="com.midea.service.esbpro.abstraction.atomic.technology_helloesbservice.v1.HelloEsbService"/>
    <property name="address" value="http://localhost:8015/cxf/cxf/userWS?wsdl"/>
</bean>

11. 查看wsdl2java 帮助

wsdl2java -help

wsdl2java -fe|-frontend <front-end-name> -db|-databinding <data-binding-name> -wv <wsdl-version> -p <[wsdl-namespace =]package-name>* -sn <service-name> -b <binding-file-name>* -reserveClass <class-name>* -catalog <catalog-file-name> -d <output-directory> -compile -classdir <compile-classes-directory> -impl -server -client -clientjar <jar-file-name> -all -autoNameResolution -allowElementReferences|-aer<=true> -defaultValues<=class-name-for-DefaultValueProvider> -ant -nexclude <schema-namespace [= java-package-name]>* -exsh <(true, false)> -noTypes -dns <Default value is true> -dex <(true, false)> -validate<[=all|basic|none]> -keep -wsdlLocation <wsdlLocation> -xjc<xjc-arguments>* -asyncMethods<[=method1,method2,...]>* -bareMethods<[=method1,method2,...]>* -mimeMethods<[=method1,method2,...]>* -noAddressBinding -faultSerialVersionUID <fault-serialVersionUID> -encoding <encoding> -exceptionSuper <exceptionSuper> -seiSuper <seiSuper>* -mark-generated -h|-?|-help -version|-v -verbose|-V -quiet|-q|-Q -wsdlList <wsdlurl> 

Options: 

   -fe|-frontend <front-end-name>
                     Specifies the front end. (defaults to JAXWS)

   -db|-databinding <data-binding-name>
                     Specifies the data binding. (defaults to JAXB)

   -wv <wsdl-version>
                     Specifies the WSDL version. (default is WSDL1.1)

   -p <[wsdl-namespace =]package-name>*
                     Specifies the java package name to use for the generated
                     code. Optionally specify a WSDL namespace to Java package
                     name mapping.

   -sn <service-name>
                     Specify he WSDL service name to use for the generated code.
                     Also, optionally specify the WSDL namespace.

   -b <binding-file-name>*
                     Specify an external jaxws or jaxb binding files. Use one -b
                     flag for each binding file.

   -reserveClass <class-name>*
                     Reserve a class name to keep the code generator from
                     generating a class of the given name. In name cases, a
                     binding file or use of -autoNameResolution flag may be
                     necessary for the code generator to completely generate
                     usable code.

   -catalog <catalog-file-name>
                     Specify catalog file to map the imported wsdl/schema.

   -d <output-directory>
                     Specify the directory into which the code is placed.

   -compile          Specifies that the generated code is compiled by the tool.

   -classdir <compile-classes-directory>
                     Specifies the directory into which compiled class files are
                     placed.

   -impl             Specifies that a dummy service implementation is generated.

   -server           Specifies that server code is generated.

   -client           Specifies that client code is generated.

   -clientjar <jar-file-name>
                     Package all the client classes and wsdl in a jar file

   -all              Specifies that interfaces, types , service, server , dummy
                     impl, client and ant script are generated.

   -autoNameResolution
                     Specifies that the tool will attempt to resolve class
                     naming conflicts without requiring the use of binding
                     customizations.

   -allowElementReferences|-aer<=true>
                     allowElementReferences

   -defaultValues<=class-name-for-DefaultValueProvider>
                     Specifies that default values are generated for the dummy
                     implementation and client. You can specify the name of the
                     class to provide the default values. The default is
                     RandomValueProvider.

   -ant              Specifies that an ant build script is generated for the
                     project.

   -nexclude <schema-namespace [= java-package-name]>*
                     Specifies a WSDL namespace to exclude when generating code.
                     This option can be specified multiple times. Optionally
                     specify the Java package name to use for the WSDL
                     namespace.

   -exsh <(true, false)>
                     Enables the processing of extended SOAP header message
                     binding.

   -noTypes          Turns off generating types

   -dns <Default value is true>
                     Enables loading the default namespace package name mapping.
                     The default is true.

   -dex <(true, false)>
                     Enable loading the default excludes namespace mapping. The
                     default is true.

   -validate<[=all|basic|none]>
                     Specifies that the WSDL is validated before generating the
                     code. Using this option is highly recommended. By default,
                     only very basic validation is done to make sure the WSDL
                     meets the WSI-BasicProfile standards that CXF requires.
                     -validate=none can turn off those checks while -validate or
                     -validate=all turns on additional schema validation and
                     other checks.

   -keep             Specifies that existing code will not be over written.
                     NOTE: You will have to solve any resulting compilation
                     problems by yourself

   -wsdlLocation <wsdlLocation>
                     Specifies the value of the @WebServiceClient annotation‘s
                     wsdlLocation property.

   -xjc<xjc-arguments>*
                     Specifies a comma separated list of arguments that are
                     passed directly to XJC when the JAXB data binding is used.
                     This option causes XJC to load additional plugins that
                     augment code generation. For example to load the
                     toString(ts) plugin that will add a toString() method to
                     all generated types the following <xjc arguments> would be
                     used: -xjc-Xts A list of available XJC plugins can be
                     obtained by using -xjc-X.

   -asyncMethods<[=method1,method2,...]>*
                     Specifies a comma separated list of methods that should
                     have asynchronous version generated in addition to the
                     normal synchronous versions. If no methods are listed, all
                     methods are generated with asynchronous versions.

   -bareMethods<[=method1,method2,...]>*
                     Specifies a comma separated list of methods that should not
                     be unwrapped into individual parameters and instead be left
                     in their "bare" form.

   -mimeMethods<[=method1,method2,...]>*
                     Specifies a comma separated list of methods where the
                     mime:content information is used to generate the type.

   -noAddressBinding Specifies that the generator should not use the address
                     jaxb binding file to map wsa:EndpointReferenceType or
                     wsa:EndpointReference to
                     javax.xml.ws.wsaddressing.W3CEndpointReference.

   -faultSerialVersionUID <fault-serialVersionUID>
                     Specifies how to generate fault Exception‘s SUID, can use
                     NONE|TIMESTAMP|FQCN|####", the default is NONE. FQCN uses a
                     hash of the fully qualified class name. #### would be any
                     valid Long to use as the SUID.

   -encoding <encoding>
                     Specifies the charset encoding to use when generating java
                     sources

   -exceptionSuper <exceptionSuper>
                     Specifies the superclass to use for generated exceptions,
                     the default is java.lang.Exception.

   -seiSuper <seiSuper>*
                     Specifies the SuperInterface to use for generated Service
                     Interfaces.

   -mark-generated   Adds @Generated annotation in all java files that are
                     generated.

   -h|-?|-help       Display detailed information for options.

   -version|-v       Display the version of the tool.

   -verbose|-V       Specifies that the generator runs in verbose mode.

   -quiet|-q|-Q      Specifies that the generator runs in quiet mode.

   -wsdlList         Indicates the wsdlurl is a plain text list of wsdlurls that
                     are new line delimited. As an example the wsdlurl might
                     point to
                     http://127.0.0.1:8080/context_path/ws?formatted=false&wsdlL
                     ist=true on a cxf server.

   <wsdlurl>         wsdl-url
时间: 2024-08-09 22:01:00

cxf http 代码自动生成的相关文章

cxf客户端代码自动生成

首先到cxf官方网站下载cxf的组件:http://cxf.apache.org/download.html 下载解压后, cmd命令到D:\apache-cxf-3.0.1\bin目录下 输入命令:wsdl2java -p com.cpic.webservice.cxf -d d:\cxf\src -all  url?wsdl 其中 -p 也就是package 对应java中的包:-d 输入目录,生成.java文件会在该目录,会自动添加-p参数配置的包路径 -client 生成客户端测试web

MyBatis代码自动生成

MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生成器自动生成实体类.DAO接口和Mapping映射文件.这样可以省去很多的功夫,将生成的代码copy到项目工程中即可. 使用自动生成有很多方式,可以在eclipse中安装插件,但是以下将要介绍的这种方式我认为很轻松,最简单,不需要装插件,只需要下几个jar包即可,把它们放在一个目录下面. 生成代码需要的文件和ja

如何根据动态SQL代码自动生成DTO

当前的状况 一般做数据库相关开发, 除非学习, 否则很少有人愿意直接使用JDBC.本来Java代码就比较啰嗦了,而直接用JDBC写代码之啰嗦简直有些令人发狂!所以在实际开发过程中,我们通常都会使用一些框架/库来帮助我们操作数据库.而且开源市场上的选择也比较多,就我个人接触到的有:Hibernate,MyBatis,JdbcTemplate,DbUtils,ActiveRecord,JavaLite等等. 这些框架都能大幅的提高开发效率,对于一些基本CRUD操作来说,虽然各有差异,但总的来说基本是

mybatis-generator 代码自动生成插件

Hibernate 可以选择MyEclipse Datebase Explorer 或者是 Hibernate-tools 等工具来自动生成映射文件和实体类. mybatis 当然也要有!下面简单介绍一个代码自动生成插件:mybatis-generator. mybatis-generator有三种用法:命令行.eclipse插件.maven插件. 作为一个使用idea开发的程序猿来说势必选择maven插件了.其他两种方式就不再此介绍了,因为我没有用过啊--- 仅仅需要简单的三步就可以啦,就是这

STM32代码自动生成工具使用说明

1.什么是"代码自动生成工具" 为了降低开发者的开发门槛,缩短开发周期,降低开发资源投入,机智云推出了代码自动生成服务.云端会根据产品定义的数据点生成对应产品的设备端代码. 自动生成的代码实现了机智云通信协议的解析与封包.传感器数据与通信数据的转换逻辑,并封装成了简单的API,且提供了多种平台的实例代码.当设备收到云端或APP端的数据后,程序会将数据转换成对应的事件并通知到应用层,开发者只需要在对应的事件处理逻辑中添加传感器的控制函数,就可以完成产品的开发. 使用自动生成的代码开发产品

mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap

由于mybatis简单易学,比起Hibername来,更容易上手,代码也能自动生成.这几天研究了下代码自动生成的,参考: http://0609xiaohua.iteye.com/blog/1453570 但是把代码复制进来,运行了下,却跑不起来,报以下错误: Exception in thread "main" java.lang.ExceptionInInitializerError at com.test.Test.main(Test.java:12)Caused by: org

Mybatis最入门---代码自动生成(generatorConfig.xml配置)

第一种方式:通过Main方法执行配置文件. ------------------------------------------------------------------------------------------------------------------------------------- 1.创建本文我们将使用的工程Mybatis13,工程结构图如下:[重点文件我们给出,其他配置文件请读者参考前文工程] 2.修改jdbc.properties文件,具体内容如下: jdbc.

代码自动生成工具,2小时搞定智能硬件产品Demo

常见的智能硬件设备多是由单片机.微处理器.微控制器等构成的嵌入式系统,通过WIFI.蓝牙.GPRS等无线通信技术连接云服务器,传统的开发方式需要开发人员根据自己的产品功能完成MCU 通过无线通信/芯片模组与云服务器交互的协议,而通过MCU代码自动生成工具,云端会根据产品定义的数据点生成对应产品的设备端代码.使用自动生成的代码开发产品,就不必再处理协议相关的部分,开发者可以将节省出来的精力集中在产品的核心功能开发上,不必重复"造轮子". 使用MCU.手机APP代码自动生成工具,2小时搞定

iBatis 代码自动生成工具 iBator 及 Example 使用

iBator的下载和安装 官方下载地址:http://people.apache.org/builds/ibatis/ibator/ 安装:见<Eclipse 插件安装> 安装完成后,“File” —> "New" —> "Other..." iBatis 代码自动生成工具 iBator - 低调的华丽 - 辉色空间 选择项目名 —> "New" —> "Other..." —> “N