首页 > 学院 > 开发设计 > 正文

在 Spring 配置文件中导入 CXF 提供 Schema、XML 详情

2019-11-08 01:48:42
字体:
来源:转载
供稿:网友

本文转载:http://blog.csdn.net/cheng_feng_xiao_zhan/article/details/52959479

 3 . 在 SPRing 配置文件中导入 CXF 提供 Schema、xml(cxf.jar 包里提供)                * Schema 文件                        <beans xmlns:jaxws="http://cxf.apache.org/jaxws"                                 xsi:schemaLocation="                                        http://cxf.apache.org/jaxws //命名空间                                        http://cxf.apache.org/schemas/jaxws.xsd">//物理路径                * XML 的配置文件                        <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"/>

 * 下面是一个简单的xml配置文件,我们来分析如何导入 CXF 提供 Schema、XML

[html] view plain copy 在CODE上查看代码片<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"      xmlns:p="http://www.springframework.org/schema/p"       xmlns:jaxws="http://cxf.apache.org/jaxws"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="          http://cxf.apache.org/jaxws          http://cxf.apache.org/schemas/jaxws.xsd          http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans.xsd">      <!-- Web应用的类加载路径有两类      1.WEB-INF/classes目录      2.WEB-INF/lib目录下       -->      <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"/>      <!-- 注册Service -->      <bean id="userService" class="org.fjava.cxf.service.UserServiceImpl"/>      <bean id="helloWorldWs" class="org.fjava.cxf.ws.impl.HelloWorldWs"      p:userService-ref="userService"/>      <!-- implementor指定WebService的服务提供者      1.直接给定服务器提供者类名      2.设置为容器中的Bean,要在Bean的id前加上#号       -->      <jaxws:endpoint implementor="#helloWorldWs" address="/getAllFoods">          <!-- 添加了两个In拦截器 -->          <jaxws:inInterceptors>              <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/><!-- 嵌套Bean,创建一个Bean -->              <bean class="org.fjava.cxf.ws.auth.AuthInterceptor"/>              <!-- <ref bean="anotherInterceptor">引用一个已有的Bean -->          </jaxws:inInterceptors>          <!-- 需要配置Out拦截器,使用<jaxws:outInterceptors> -->      </jaxws:endpoint>      <!-- <jaxws:endpoint implementor="org.fjava.cxf.ws.impl.HelloWorldWs" address="/getAllFoods">      </jaxws:endpoint> -->  </beans>  

 *%20 在 spring 配置文件中导入%20CXF%20提供%20Schema%20文件,在%20cxf.jar%20包里提供:

 %20 %20 %20 

       

       导入效果:

[html] view plain copy 在CODE上查看代码片<beans xmlns="http://www.springframework.org/schema/beans"      xmlns:p="http://www.springframework.org/schema/p"       xmlns:jaxws="http://cxf.apache.org/jaxws"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="          http://cxf.apache.org/jaxws          http://cxf.apache.org/schemas/jaxws.xsd          http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans.xsd">   *%20导入%20CXF%20的%20XML%20文件:

 %20 %20 %20 

       导入效果:

[html] view plain copy 在CODE上查看代码片<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"/>  若导入%20XML%20文件错误,运行服务端报错:

[html] view%20plain copy 派生到我的代码片十月 28, 2016 11:40:53 下午 org.apache.catalina.core.StandardContext listenerStart  严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener  org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/cxf/cxff.xml]  Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/cxf/cxff.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/cxf/cxff.xml] cannot be opened because it does not exist      at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)      at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)      at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)  Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/cxf/cxff.xml]

修改正确 XML 的导入路径即可!

希望对你有帮助,祝你有一个好心情,加油!

若有错误、不全、可优化的点,欢迎纠正与补充;转载请注明出处!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表