加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

CXF之HelloWorld

发布时间:2020-12-17 01:26:52 所属栏目:安全 来源:网络整理
导读:?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/j2eehttp://java.sun.com/xml/ns/j2ee/web
<?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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读