使用cxf的相关jar包搭建webservice 发布接口 测试接口

cxf3.0.4结合spring搭建webservice服务端的框架必需的最少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服务,也就是运行到时出错

缺少: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引入的话则下面三句不用了,因为框架引入了
配置文件中不需要:

[html] view plain copy

web.xml中添加cxf的servlet
[html] view plain copy

CXFService
org.apache.cxf.transport.servlet.CXFServlet

CXFService
/webservice/*

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

下面的自己通过以上写的接口代码
创建类

@WebService
public interface hrService {
	public String getUserInfo(String searchparm);
}
@WebService
public class hrServiceImpl implements hrService{
	@Resource(name="employService")
	@Autowired
	private EmployService employService;
	@Resource(name="dataObjectService")
	@Autowired
	private DataObjectService dataObjectService;
	@Override
	public String getUserInfo(String empcode) {
		String sql="";
		if (!empcode.equals(" ")) {
		 sql="select * from emps  "
					+ "where "+empcode.replaceAll("&", "and ");
		}else {
			sql="select * from emps  ";
		}
		List<LinkedHashMap<String, String>> datahr=dataObjectService.executeSelectSql2(sql);
		String  param= JSON.toJSONString(datahr);
		return param;
	}

}

然后访问下接口

public class getUserInfo {
public static void main(String[] args) {
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();  
	    factoryBean.setServiceClass(hrService.class);  
	    factoryBean.setAddress("http://localhost:8080/qwe/ws/getUserInfo?wsdl");  
	    hrService readerService = (hrService)factoryBean.create();
	    String reader = readerService.getUserInfo("empcode='209'");
	    System.out.println("Reader:"+reader); 
	}


}

看了这位大神的博客:蓝色飞刀

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Apache CXF是一个开源的WebService框架,可以帮助用户快速、简便地开发和部署WebService应用程序。它提供了多种方式来调用WebService接口,下面介绍几种常用的方式: 1. 使用JAX-WS API:CXF实现了JAX-WS API,可以直接使用JAX-WS提供的API来调用WebService。示例代码如下: ```java HelloWorldService service = new HelloWorldService(); HelloWorld port = service.getHelloWorldPort(); String result = port.sayHello("CXF"); ``` 2. 使用代理方式:CXF可以根据WebService WSDL文件自动生成代理类,然后通过调用代理类的方法来调用WebService接口。示例代码如下: ```java JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://localhost:8080/HelloWorld"); HelloWorld client = (HelloWorld) factory.create(); String result = client.sayHello("CXF"); ``` 3. 使用Spring配置文件:CXF提供了Spring配置文件方式来实现WebService接口的调用。用户可以在Spring配置文件中配置WebService客户端,然后通过Spring容器来获取WebService客户端实例。示例代码如下: ```xml <jaxws:client id="helloClient" serviceClass="com.example.HelloWorld" address="http://localhost:8080/HelloWorld"/> ``` ```java ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml"); HelloWorld client = (HelloWorld) context.getBean("helloClient"); String result = client.sayHello("CXF"); ``` 以上是几种常用的调用WebService接口的方式,可以根据具体情况选择适合自己的方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值