1、服务器端
package cxf;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String text) ;
}
package cxf;
import javax.jws.WebService;
@WebService
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String text) {
return "55555555555555555555555" + text ;
}
}
spring-cxf.xml
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd">
web.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
org.springframework.web.context.ContextLoaderListener
org.apache.cxf.transport.servlet.CXFServlet
2、客户端
package cxf;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
package cxf;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(System.getProperty("java.endorsed.dirs"));
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-cxf.xml");
HelloWorld client = (HelloWorld) ctx.getBean("cxfClient");
String result = client.sayHello("你好!");
System.out.println(result);
}
}
spring-cxf.xml
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd">
web.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
org.springframework.web.context.ContextLoaderListener
org.apache.cxf.transport.servlet.CXFServlet
注意:
1、发生如下错误时候
nested exception is java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)
解决方法:
System.out.println(System.getProperty("java.endorsed.dirs"));能取得存放目录
将jaxb-api.jar包放到%{JAVA_HOME}\jre\lib\endorsed下即可,如果没有endorsed,则新建一个.这两个jar包我放提供在附件里
2、javamail异常:java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport
解决方法:
D:\Program Files\MyEclipse 6.0\myeclipse\eclipse\plugins\com.genuitec.eclipse.j2eedt.core_6.0.1.zmyeclipse601200710\data\libraryset\EE_5
javaee.jar包中的 mail和 activation
我将着两项删除了,我使用的是javaee5
问题被解决了