CXF之HelloWorld

<?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">
	-->
<web-app xmlns:j2ee="http://java.sun.com/xml/ns/j2ee">

	<display-name>demo</display-name>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:/applicationContext*.xml</param-value>
	</context-param>


	<!-- Hibernate Open Session In View filter-->
	<filter>
		<filter-name>hibernateOpenSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>hibernateOpenSessionInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!--Spring ApplicationContext 载入 -->
	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<!-- Spring 刷新Introspector防止内存泄露 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>

	<!-- CXF 配置 -->
	<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>/services/*</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

 

--------------以上是web.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:cxf="http://cxf.apache.org/core"
	xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
	default-autowire="byType" default-lazy-init="true">

	<description>使用Apache CXF的Web Service配置文件</description>


	<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" />


    <!-- WebService的实现Bean定义   id(service_Hello)要和下面ref一样,可以理解为通过address(/Hello)
    	找到service_Hello,继而找到实现类Hello
    -->
	<bean id="service_Hello" class="Hello">
	</bean>
	
	<!-- jax-ws endpoint定义  -->
	<jaxws:endpoint address="/Hello">
		<jaxws:implementor ref="service_Hello" />
	</jaxws:endpoint>


</beans>

 

 

------------------以上是CXF在spring中关于WebService的配置----------------------------------------------------

 

还有两个简单的类

 

import javax.jws.WebService;


//注意这里标注为WebService
@WebService
public interface IHello
{

    public String SayHello();
}

 

public class Hello implements IHello
{

    public String SayHello()
    {
        return "Hi CXF!";
    }

}

 

 

预览效果的话:http://localhost:8080/cxf/services

 

这里的services就是web.xml配置的servlet。

 

另外想测试服务是否可用-vs下添加web引用。我不会写java webservice client。

------------------------------------------------------

 

下载的时候看到下载地址很有意思:renren

http://labs.renren.com/apache-mirror//cxf/2.2.10/apache-cxf-2.2.10.tar.gz

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值