我正在使用Maven 3.0.3和Spring 3.1.1.RELEASE。我想自动装配一个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>
但是,我对如何设置Spring应用程序上下文感到困惑。我有
<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>
但是我收到了这个错误。请注意“相关原因:WSDL元数据不可用于创建代理”。如何正确配置此内容?
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 'organizationWebService' 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
答案 0 :(得分:1)
您缺少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>
使用上面的配置,它应该可以工作。
答案 1 :(得分:0)
面对同样的问题,事实证明,我错过了这些依赖:
<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>
将它们添加到我的类路径解决了这个问题。