按照CXF官方网站的步骤,可Client调用的时候确出现
javax.xml.ws.WebServiceException: Could not find operation info for web method sayHi.
的异常.大家帮我看看,很着急,多谢多谢! 接口HelloWorld 代码如下: package com.lbg.ws.test
import javax.jws.WebService;
@WebService(name="HelloWorld")
public interface HelloWorld {
@WebMethod(operationName="sayHi")
String sayHi(String text);
} 实现类HelloWorldImpl 代码如下: package com.lbg.ws.test
@WebService(endpointInterface="com.lbg.ws.test.IHelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
} beans.xml如下:
<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"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-javascript-client.xml"/> <bean id="helloWorldImpl" class="com.lbg.ws.test.impl.HelloWorld"/>
<jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl"
address="/HelloWorld"/>
Web.xml 的配置
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>client的xml如下:
<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-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" class="com.tjsoft.HelloWorld"
factory-bean="clientFactory" factory-method="create" /> <bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.tjsoft.HelloWorld" />
<property name="address" value="http://192.9.207.230:8080/dzmd/services/HelloWorld" />
</bean> Client调用代码如下: package com.tjsoft;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;public final class ClientServer{
private ClientServer(){
}
public static void main(String args[]) throws Exception{
String str="WebRoot/WEB-INF/applicationContext.xml";
ApplicationContext context = new FileSystemXmlApplicationContext(str);
HelloWorld client = (HelloWorld) context.getBean("client");
String response = client.sayHello("邓建利");
System.out.println("结果: " + response);
System.exit(0);
}
}
访问http://192.9.207.230:8080/dzmd/services/HelloWorld?wsdl内容也可以显示
javax.xml.ws.WebServiceException: Could not find operation info for web method sayHi.
的异常.大家帮我看看,很着急,多谢多谢! 接口HelloWorld 代码如下: package com.lbg.ws.test
import javax.jws.WebService;
@WebService(name="HelloWorld")
public interface HelloWorld {
@WebMethod(operationName="sayHi")
String sayHi(String text);
} 实现类HelloWorldImpl 代码如下: package com.lbg.ws.test
@WebService(endpointInterface="com.lbg.ws.test.IHelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
} beans.xml如下:
<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"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-javascript-client.xml"/> <bean id="helloWorldImpl" class="com.lbg.ws.test.impl.HelloWorld"/>
<jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl"
address="/HelloWorld"/>
Web.xml 的配置
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>client的xml如下:
<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-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" class="com.tjsoft.HelloWorld"
factory-bean="clientFactory" factory-method="create" /> <bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.tjsoft.HelloWorld" />
<property name="address" value="http://192.9.207.230:8080/dzmd/services/HelloWorld" />
</bean> Client调用代码如下: package com.tjsoft;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;public final class ClientServer{
private ClientServer(){
}
public static void main(String args[]) throws Exception{
String str="WebRoot/WEB-INF/applicationContext.xml";
ApplicationContext context = new FileSystemXmlApplicationContext(str);
HelloWorld client = (HelloWorld) context.getBean("client");
String response = client.sayHello("邓建利");
System.out.println("结果: " + response);
System.exit(0);
}
}
访问http://192.9.207.230:8080/dzmd/services/HelloWorld?wsdl内容也可以显示
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货