晕死啊,今天弄了一天的cxf都是冒not valid错误
在tamcat5.0.28启动的时候只是显示监听没建好,后来换到tomcat6时报了
JAXB 2.0 API is being loaded from the bootstrap classloader 错误
后面上网查了下是http://queue19.javaeye.com/blog/418748
按照网上看说,在jdk1.6.0_05/jre/lib/下新建endorsed文件夹,放入jaxb-api.jar还是没有效果,经过我的仔细阅读E文,纠正这个错误,如果是Tomcat 5.5,则新建文件路径为“Tomcat 5.5/common/endorsed”,如果是Tomcat 6.0,则新建路径为“Tomcat 6.0/endorsed”。不是在jdk1.6.0_05/jre/lib/
按照上面说的把 那两个包这放到tamcat5.0.28后不冒not valid了,但是换了一个错误:provider org.apache.xalan.processor.TransformerFactoryImpl not found
再上网查,发现是和endorsed文件夹下的xercesImpl.jar,xml-apis.jar 冲突了,把它们移出来就成功了。。
描述下今天的活:
1. 首先新建一个web project,起名为cxfTest
2. 然后把apache-cxf-2.1的lib里面的包全部拷贝到lib文件夹
3. 接着开始编写代码
Spring-bean.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-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="hello" class="com.helloWorldTest.service.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello"
address="/HelloWorld" />
</beans>
Web.xml---------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-bean.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>
</web-app>
HelloWorld.java------------------------------------------------------------------------------
package com.helloWorldTest.service;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
HelloWorldImpl.java---------------------------------------------------------------------------
package com.helloWorldTest.service;
import javax.jws.WebService;
@WebService(endpointInterface="com.helloWorldTest.service.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String text) {
return "Hello" + text ;
}
}
4. 最后,发布到服务器上,打开浏览器,输入地址http://localhost:8088/cxfTest/HelloWorld?wsdl
看到结果,成功了~~,终于发布成功:
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions name="HelloWorldImplService" targetNamespace="http://service.helloWorldTest.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.helloWorldTest.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wsdl:types>
- <xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://service.helloWorldTest.com/" xmlns:tns="http://service.helloWorldTest.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sayHello" type="tns:sayHello" />
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse" />
- <xs:complexType name="sayHello">
- <xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string" />
</xs:sequence>
</xs:complexType>
- <xs:complexType name="sayHelloResponse">
- <xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
- <wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters" />
</wsdl:message>
- <wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters" />
</wsdl:message>
- <wsdl:portType name="HelloWorld">
- <wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello" />
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHello">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHelloResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorldImplService">
- <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://localhost:8088/cxfTest/HelloWorld" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>