Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Spring和嵌入式Jetty 8发布JAX-WS服务_Spring_Maven_Jax Ws_Netbeans 7_Embedded Jetty - Fatal编程技术网

使用Spring和嵌入式Jetty 8发布JAX-WS服务

使用Spring和嵌入式Jetty 8发布JAX-WS服务,spring,maven,jax-ws,netbeans-7,embedded-jetty,Spring,Maven,Jax Ws,Netbeans 7,Embedded Jetty,我正在尝试将JAX-WS web服务添加到我的嵌入式Jetty应用程序中。web服务客户端将是一个.NET应用程序 我的项目是在Netbeans 7.1.1中作为Maven应用程序创建的。它使用Spring3.0 我采取以下步骤将JAX-WS添加到我的应用程序中: 将jaxws-spring添加到pom.xml中 <dependency> <groupId>org.jvnet.jax-ws-commons.spring</groupId> &l

我正在尝试将JAX-WS web服务添加到我的嵌入式Jetty应用程序中。web服务客户端将是一个.NET应用程序

我的项目是在Netbeans 7.1.1中作为Maven应用程序创建的。它使用Spring3.0

我采取以下步骤将JAX-WS添加到我的应用程序中:

  • 将jaxws-spring添加到pom.xml中

    <dependency>
        <groupId>org.jvnet.jax-ws-commons.spring</groupId>
        <artifactId>jaxws-spring</artifactId>
        <version>1.8</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 为我的服务创建了一个实现类

    @WebService(name = "GenerateUEIDService")
    public class GenerateUEIDService {
    
        @WebMethod(operationName = "generateUniqueIds")
        public String generateUniqueIds() {
            return "Hello World";
        }
    
    }
    
  • 在Spring applicationContext.xml文件中配置我的服务

    <bean id="generateUEIDService" class="com.mycompany.GenerateUEIDService"/>
    
    <wss:binding url="/service/GenerateUEID.svc">
     <wss:service>
      <ws:service bean="#generateUEIDService" />
     </wss:service>
    </wss:binding>  
    
    
    
  • 在上面的步骤3中,我没有在Netbeans中使用任何Web服务创建向导。相反,我创建了GenerateUIDService作为一个普通的Java类,但添加了注释。尽管我没有发现Netbeans,但它确实检测到这是一个Web服务,因为它在项目视图中创建了一个“Web服务”节点,其下有“GenerateUEIDServiceService”。如果展开GenerateUEIDServiceService,我会看到“GenerateUniqueId:String”

    它似乎建得很好。但当我运行应用程序时,我得到:

    com.sun.xml.ws.model.RuntimeModelerException:运行时建模器错误:包装类 找不到com.mycompany.jaxws.GenerateUniqueIds。你有没有倾向于生成它们

    嗯,不,我还没有产生任何东西。考虑到我的配置,我应该怎么做?我需要在pom.xml中添加插件吗?还是Netbeans神奇地为我生成了包装器


    请注意,我的web服务客户端将是.NET。所以我假设我应该使用document/literal wrapped的默认SOAPBinding。

    您可以使用Maven插件生成jaxb类。应该是这样的:

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <!--
            <generatePackage>if you wan to force the package</generatePackage>
            -->
            <generateDirectory>target/jaxb/generate/</generateDirectory>
            <schemaDirectory>src/main/webapp/WEB-INF/</schemaDirectory>
            <includeSchemas>
                <includeSchema>yourXSDfile.xsd</includeSchema>
            </includeSchemas>
        </configuration>
    </plugin>
    
    
    org.jvnet.jaxb2.maven2
    maven-jaxb2-plugin
    0.8.1
    生成
    1.6
    1.6
    target/jaxb/generate/
    src/main/webapp/WEB-INF/
    yourXSDfile.xsd
    
    我决定创建一个简单的Netbeans Maven java应用程序,看看服务的包装类是否会自动生成。事实证明,它们是由JAX-WS运行时在运行时动态创建的

    [exec:exec]
    Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
    INFO: Dynamically creating request wrapper Class com.mycompany.mavenjaxwsjetty.jaxws.Greet
    Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
    INFO: Dynamically creating response wrapper bean Class com.mycompany.mavenjaxwsjetty.jaxws.GreetResponse
    
    所以回到我的原始申请(从上面的原始帖子)。出于不相关的原因,我删除了jaxws-spring。我可能做了一些我想不起来的其他改变。现在,当我运行该应用程序时,我可以在日志中看到正在创建包装器类

    所以我想我的问题的答案是Netbeans并没有神奇地为我创建包装器类,而是jax ws运行时创建的


    我仍然想知道在什么情况下包装器类不会自动为我生成。或者当我想使用wsgen或maven-jaxb2-plugin生成自己的插件时。像往常一样,我想“剥猫皮”的方法不止一种,每种方法都有其优缺点。

    谢谢你的回答。我还没有创建XSD。我希望为我动态创建WSDL和XSD。看来jaxws运行时正在为我做这件事。我明白了。我不明白你的问题。
    [exec:exec]
    Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
    INFO: Dynamically creating request wrapper Class com.mycompany.mavenjaxwsjetty.jaxws.Greet
    Jul 12, 2012 8:30:05 AM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
    INFO: Dynamically creating response wrapper bean Class com.mycompany.mavenjaxwsjetty.jaxws.GreetResponse