使用cxf3.0.4搭建webservice服务需要的最精简jar包

        网上看了百度了好长时间,头都大了,还是没有把想要的最简jar包找到,不是jar仍然很多,就是jar包少了,导致报错。无奈之下,自己花了一个下午,采用用逆推法,总结了下cxf3.0.4结合spring搭建webservice服务端的框架必需的最少jar包。

      方法很笨,但是很有效:直接先加载cxf3.0.4中lib下的所有jar包,结合spring搭建一个最简单的webservice服务框架。然后逐个删除项目下的cxf相关的jar包。

     下面是测试结果,只列出报错了的测试:

1、org.apache.catalina.LifecycleException: A child container failed during start
缺少:cxf-core-3.0.4.jar(最核心的包,不多说)


2、java.lang.ClassNotFoundException: org.apache.cxf.binding.soap.SoapBindingConfiguration
缺少:cxf-rt-bindings-soap-3.0.4.jar       (soap协议)

3、org.apache.cxf.jaxb.JAXBDataBinding:
缺少:cxf-rt-databinding-jaxb-3.0.4.jar      


4、加载Application文件时出现Unable to locate Spring NamespaceHandler for XML schema namespace
     [http://cxf.apache.org/jaxws]

缺少:cxf-rt-frontend-jaxws-3.0.4.jar    (frontend 前置的意思,你懂的)

5、org/apache/cxf/frontend/spring/ClientProxyFactoryBeanDefinitionParser错误:
缺少:cxf-rt-frontend-simple-3.0.4.jar


6、class path resource [META-INF/cxf/cxf-servlet.xml] cannot be opened because it does not exist
缺少:cxf-rt-transports-http-3.0.4.jar


7、org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://cxf.apache.org/transports/udp.
缺少:cxf-rt-transports-udp-3.0.4.jar


8、org.apache.cxf.ws.discovery.internal.WSDiscoveryServiceImpl startup
警告: Could not start WS-Discovery Service.
javax.xml.ws.WebServiceException: java.lang.NullPointerException
不能初始化配置的bean服务,也就是运行到<jaxws:server>时出错

缺少:cxf-rt-ws-addr-3.0.4.jar

9、java.lang.ClassNotFoundException: org.apache.cxf.ws.policy.AssertionInfoMap
缺少:cxf-rt-ws-policy-3.0.4.jar        


10、java.lang.ClassNotFoundException: org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
缺少:cxf-rt-wsdl-3.0.4.jar

11、java.lang.ClassNotFoundException: org.apache.neethi.AssertionBuilderFactory
缺少:neethi-3.0.3.jar

12、java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
缺少:slf4j-api-1.7.9.jar

13、java.lang.ClassNotFoundException: org.apache.ws.commons.schema.resolver.URIResolver
缺少:xmlschema-core-2.2.1.jar


所以,总结cxf3.0.4框架必需的包为:
cxf-core-3.0.4.jar
cxf-rt-bindings-soap-3.0.4.jar
cxf-rt-databinding-jaxb-3.0.4.jar
cxf-rt-frontend-jaxws-3.0.4.jar
cxf-rt-frontend-simple-3.0.4.jar
cxf-rt-transports-http-3.0.4.jar
cxf-rt-transports-udp-3.0.4.jar
cxf-rt-ws-addr-3.0.4.jar
cxf-rt-wsdl-3.0.4.jar
cxf-rt-ws-policy-3.0.4.jar
cxf-rt-wsdl-3.0.4.jar
neethi-3.0.3.jar
slf4j-api-1.7.9.jar
xmlschema-core-2.2.1.jar

注意:这里不包括spring依赖包和commoms下的jar包


引入CXF Bean定义如下,早期的版本中使用,如果是servlet引入的话则下面三句不用了,因为框架引入了 
配置文件中不需要:
 <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" />

 <!-- scope="singleton"单例 -->
   <bean id="userServiceBean" class="com.winit.webservice.UserWebService">
   </bean>
    <!-- 注意下面的address,这里的address的名称就是访问的WebService的name --> 
    <jaxws:server id="userService" serviceClass="com.winit.webservice.IUserWebService" address="/Users">    
	    <jaxws:serviceBean>         
	        <!-- 要暴露的 bean 的引用 -->        
	        <ref bean="userServiceBean"/>     
	    </jaxws:serviceBean>     
   </jaxws:server>

web.xml中添加cxf的servlet

  <servlet>  
      <servlet-name>CXFService</servlet-name>  
      <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
  </servlet>          
  <servlet-mapping>  
      <servlet-name>CXFService</servlet-name>  
      <url-pattern>/webservice/*</url-pattern>  
  </servlet-mapping> 


项目名是 WebAdvanced,服务启动后,访问链接:
http://localhost:8080/WebAdvanced/webservice/Users?wsdl。说明发布的webservice服务成功。


最后,“尽信书则不如无书”,当你无路可走,没有好的思路时,最笨的方法,往往是最直接有效的方法。






只要在maven项目上加了下面这段代码发布webservice 就报错(我自己写的demo是正常的): <bean id="schoolNewsBean" class="com.edulife.ws.impl.SchoolNewsImpl"> </bean> <!-- 要发布成webservice的bean --> <jaxws:endpoint implementor="#schoolNewsBean" address="/CXFService"> </jaxws:endpoint> 错误信息: 2015-01-07 20:42:43,981 ERROR (org.springframework.web.context.ContextLoader:319) - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.jaxws.EndpointImpl---938321254': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:371) at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251) at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1608) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1549) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) ... 21 more Caused by: org.apache.cxf.service.factory.ServiceConstructionException at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:341) at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86) at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:490) at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704) at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:550) at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265) at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215) at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102) at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159) at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211) at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456) at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334) ... 30 more Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions Class has two properties of the same name "tSort" this problem is related to the following location: at public int com.edulife.model.merit.Dept.gettSort() at com.edulife.model.merit.Dept at public com.edulife.model.merit.Dept com.edulife.model.security.User.getDept() at com.edulife.model.security.User at private com.edulife.model.security.User com.edulife.ws.service.jaxws_asm.QuerySchoolNews.arg4 at com.edulife.ws.service.jaxws_asm.QuerySchoolNews this problem is related to the following location: at public int com.edulife.model.merit.Dept.tSort at com.edulife.model.merit.Dept at public com.edulife.model.merit.Dept com.edulife.model.security.User.getDept() at com.edulife.model.security.User at private com.edulife.model.security.User com.edulife.ws.service.jaxws_asm.QuerySchoolNews.arg4 at com.edulife.ws.service.jaxws_asm.QuerySchoolNews at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.newInstance(Unknown Source) at javax.xml.bind.ContextFinder.find(Unknown Source) at javax.xml.bind.JAXBContext.newInstance(Unknown Source) at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:356) at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:244) at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:484) at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:339) ... 41 more
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页