简体   繁体   English

如何在Spring应用程序上下文中设置Web服务客户端?

[英]How do I set up a web service client in my spring application context?

I'm using Maven 3.0.3 and Spring 3.1.1.RELEASE. 我正在使用Maven 3.0.3和Spring 3.1.1.RELEASE。 I would like to autowire a web service client, whose classes I'm generating with the jaxws-maven-plugin ... 我想自动连接一个Web服务客户端,我正在使用jaxws-maven-plugin生成其类...

<plugin>
     <groupId>org.codehaus.mojo</groupId>
             <artifactId>jaxws-maven-plugin</artifactId>
                    <executions>
                           <execution>
                                <goals>
                                  <goal>wsimport</goal>
                                 </goals>
                                 <configuration>
                                      <wsdlUrls>
                                         <wsdlUrl>${wsdl.url}</wsdlUrl>
                                      </wsdlUrls>
                                 <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                                 <packageName>org.myco.myws</packageName>
                                 </configuration>
                         </execution>
                  </executions>
</plugin>

However, I'm confused about how to setup my Spring applicaton context. 但是,我对如何设置Spring applicaton上下文感到困惑。 I have 我有

    <bean id="organizationWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
        <property name="serviceInterface" value="org.myco.myws.OrganizationWebService" />
        <property name="namespaceUri" value="http://myco.org/myws/" />
        <property name="serviceName" value="api" />
        <property name="endpointAddress" value="http://hbs-01.qa2.myco.cb:8443/bsg/myws/OrganizationService?WSDL" />
    </bean>

But I get this error. 但是我得到这个错误。 Note the "related cause: WSDL Metadata not available to create the proxy". 请注意“相关原因:WSDL元数据不可用于创建代理”。 How do I configure this thing correctly? 如何正确配置此东西?

java.lang.IllegalStateException: Failed to load ApplicationContext^M
        at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)^M
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)^M
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)^M
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)^M
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)^M
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)^M
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)^M
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)^M
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)^M
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)^M
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)^M
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)^M
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)^M
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)^M
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)^M
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)^M
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)^M
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)^M
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)^M
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)^M
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)^M
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)^M
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)^M
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)^M
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)^M
        at java.lang.reflect.Method.invoke(Method.java:597)^M
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)^M
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)^M
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)^M
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)^M
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)^
    ...
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &apos;organizationWebService&apos; defined in class path resource [testAppContextHSQL.xml]: Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service instance or ServiceEndpointInterface org.myco.myws.OrganizationWebService should have WSDL information

You are missing the WSDL document URL in your Spring configuration: 您在Spring配置中缺少WSDL文档URL:

<bean id="organizationWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="serviceInterface" value="org.myco.myws.OrganizationWebService" />
    <property name="namespaceUri" value="http://myco.org/myws/" />
    <property name="serviceName" value="api" />
    <property name="endpointAddress" value="http://hbs-01.qa2.myco.cb:8443/bsg/myws/OrganizationService" />
    <property name="wsdlDocumentUrl" value="classpath:org/myco/mywscampaignmonitor/mywscampaignmonitor.wsdl" />
</bean>

Use the configuration as above and it should work. 使用上面的配置,它应该可以工作。

Faced with the same problem, it turned out, I was missing these depedencies: 事实证明,面对相同的问题,我错过了以下缺点:

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

Just adding them to my classpath solved the problem. 只需将它们添加到我的类路径中即可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置 Spring TCP 客户端和服务器模型? - How do I set up a Spring TCP client and server model? 如何在旧版(Spring Web-MVC)代码中发现我的Service(Spring Boot应用程序) - How can I discover my Service(Spring Boot application) in legecy(Spring web-mvc) code 如何将正确的Spring上下文连接到我的Cucumber测试? - How do I wire up the correct Spring context to my Cucumber tests? 如何在spring应用程序上下文中包含两个同名文件? - How do I include two files of the same name in my spring application context? 如何在WAR应用程序中使用Spring自动装配我的webservices客户端? - How do I autowire my webservices client in my WAR application (using Spring)? 如何在我的Web应用程序之外移动spring xml配置? - How do I move my spring xml configuration outside of my web application? Spring Web应用程序上下文 - Spring web Application Context Camel OSGI:如何获得spring应用程序上下文? - Camel OSGI: how do I get the spring application context? 如何为Spring MVC / Security静态Web服务创建自定义JSON 401页面? - How do I create a custom JSON 401 page for my Spring MVC/Security restful web service? 如何在独立客户端中实例化Spring Service - How do i instantiate a spring service in a standalone client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM