maven整合webservice(cxf)的时候可能会出现的问题
来源:互联网 发布:《c专家编程》 编辑:程序博客网 时间:2024/05/16 01:45
1 使用的maven包,将cxf的jar包信息放到pom.xml中会出现错误。(cxf-rt-frontend-jaxws),将此包放入到pomxml中的时候会报错,再加入cxf-rt-transports-http包时错误会消失
贴出以下信息。
<!--webservice所需要的包-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.6</version>
</dependency>
2.配置web.xml的时候注意将以下信息放在DispatcherServlet之前。
<!--webservice-->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
3.在配置webxml时不要忘记将配置文件引入到spring的扫描路径中
4在使用@webservice注解时,可能会出现Access restriction: The type 'WebService' is not API (restriction on require....等警告,并且IDE中不会提示此标签,修复了一下就好了,原因不明,有知道的可以告诉我,共同学习
5在运行的时候可能会报错:Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/cxf/cxf-extension-soap.xml]
原因是使用了2.4以下的配置却使用的2.4以上的jar包,官方有说明如下:
Changes in CXF 2.4.x
The below is applicable for CXF versions 2.3.x and older. Starting in CXF 2.4.0, the extensions are loaded internally by CXF automatically and you do not need to import all the cxf-extension-*.xml file. You only need to import classpath:META-INF/cxf/cxf.xml.
在使用2.3或者更早的版本的时候你需要引入cxf-extension-*.xml 从2.4开始你就不用引入这个xml了只需要引入<import resource="classpath:META-INF/cxf/cxf.xml" />
5在编写cxf的同时,要注意一点为不要将@webservice的注解添加在接口上,请直接添加到实现类上,不然可能会出现的问题是,在用jaxws调用时出现XXXX是接口,而jaxws无法处理接口。
最后贴一下cxf的配置文件和helloworld
spring-cxf.xml
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:http-conf = "http://cxf.apache.org/transports/http/configuration"
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
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.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" />
<jaxws:endpoint id="hello"
implementor="com.nuotai.webservice.impl.helloWorldImpl" address="/hello" />
</beans>
helloWorld.java
package com.nuotai.webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.nuotai.model.User;
@WebService
public interface helloWorld {
@WebMethod
public String sayHello(String name);
@WebMethod
public String sayHello2(User user);
}
helloWorldImpl.java
package com.nuotai.webservice.impl;
import javax.jws.WebService;
import com.alibaba.fastjson.JSONObject;
import com.nuotai.model.User;
import com.nuotai.webservice.helloWorld;
@WebService
public class helloWorldImpl implements helloWorld {
public String sayHello(String name) {
JSONObject myJsonObject = JSONObject.parseObject(name);
String nameTemp = myJsonObject.getString("name");
/*
* String nameTemp = name.getString("name");
* System.out.println(nameTemp);
*/
return nameTemp;
}
public String sayHello2(User user) {
JSONObject json = new JSONObject();
String name = user.getUser_name();
json.put("name", name);
return json.toJSONString();
}
}
- maven整合webservice(cxf)的时候可能会出现的问题
- webService(cxf--rs_spring的整合)
- 总结:创建maven项目时可能会出现的问题
- 面试可能会出现的问题
- (四)WebService之CXF和Web程序的整合
- WebService之CXF与Spring的整合
- WebService的CXF框架整合Spring
- WebService cxf 与 ssm框架的整合
- webService(cxf--ws_Spring整合的过程)
- ssm maven项目整合出现的问题
- maven整合ssm出现的问题
- MyEclipse创建Maven工程的时候可能会碰到的问题1
- Spark和hive整合的时候出现问题
- WebService之Axis2整合Mybatis出现的问题
- maven 配置 struts2 hibernate3 spring2 的时候出现的问题
- 程序中可能会出现的问题本质
- 64未eclipse可能会出现的问题
- 安装虚拟机时可能会出现的问题
- 个人理解JAVA反射
- 如果你已经这样了,那你必须要跳槽
- 隐私政策
- SQL中如何取消数字前面的0 字母
- Python3从零学习(四)
- maven整合webservice(cxf)的时候可能会出现的问题
- elasticsearch-kibana 启用Index contains time-based events
- java中集合与数组之间的转化
- Android进程间通信(三):使用Messenger实现进程间通信
- 安卓提示信息管理
- tomcat 解析(三)-启动框架
- Web.config中的system.web system.webServer
- Android 实现切换主题皮肤功能(类似于众多app中的 夜间模式,主题包等)
- 剑指offer|链表中倒数第k个结点