葉落知秋

          一葉落而知天下秋

          統(tǒng)計(jì)

          留言簿(1)

          Java相關(guān)

          閱讀排行榜

          評(píng)論排行榜

          cxf+spring+struts2的helloWorld


           發(fā)表時(shí)間: 2007年11月30日



          參照Cxf官方的例子,用Cxf+spring+struts2寫(xiě)了一個(gè)helloWorld的例子

          首先安裝cxf的eclipse插件,文檔參考:incubator.apache.org/cxf/setting-up-eclipse.html

          Service代碼:

          HelloWorld
          1. package com.zaife.cxfspring;   
          2.   
          3.   
          4. import javax.jws.WebService;   
          5.   
          6. @WebService  
          7. public interface HelloWorld {   
          8.     String sayHi(String text);   
          9. }  
          HelloWorldImpl
          1. package com.zaife.cxfspring;   
          2.   
          3. import javax.jws.WebService;   
          4.   
          5. @WebService(endpointInterface = "com.zaife.cxfspring.HelloWorld")   
          6. public class HelloWorldImpl implements HelloWorld {   
          7.   
          8.     public String sayHi(String text) {   
          9.         return "Hello " + text;   
          10.     }   
          11. }  

           

          java 代碼
          1. package com.zaife.struts2;   
          2.   
          3. import com.opensymphony.xwork2.Action;   
          4. import com.opensymphony.xwork2.ActionSupport;   
          5. import com.zaife.cxfspring.HelloWorld;   
          6.   
          7. public class CallCxfService extends ActionSupport {   
          8.        
          9.     private HelloWorld client;   
          10.        
          11.     private String message;   
          12.   
          13.     public void setClient(HelloWorld client) {   
          14.         this.client = client;   
          15.     }   
          16.        
          17.     public String execute() {   
          18.         this.message = this.client.sayHi("dd");   
          19.         return Action.SUCCESS;   
          20.     }   
          21.   
          22.     public String getMessage() {   
          23.         return message;   
          24.     }   
          25.   
          26.     public void setMessage(String message) {   
          27.         this.message = message;   
          28.     }      
          29. }  

          Spring配置文件

          1. <beans xmlns="http://www.springframework.org/schema/beans"  
          2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          3.     xmlns:jaxws="http://cxf.apache.org/jaxws"  
          4.     xsi:schemaLocation="   
          5. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
          6. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  
          7.   
          8.     <import resource="classpath:META-INF/cxf/cxf.xml" />  
          9.     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
          10.     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />  
          11.   
          12.     <jaxws:endpoint    
          13.       id="helloWorld"    
          14.       implementor="com.zaife.cxfspring.HelloWorldImpl"    
          15.       address="/HelloWorld" />  
          16.          
          17.          
          18.   
          19.     <bean id="client" class="com.zaife.cxfspring.HelloWorld"    
          20.       factory-bean="clientFactory" factory-method="create"/>  
          21.        
          22.     <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">  
          23.       <property name="serviceClass" value="com.zaife.cxfspring.HelloWorld"/>  
          24.       <property name="address" value="http://localhost:8080/cxf-spring/test/HelloWorld"/>  
          25.     bean>  
          26.        
          27.     <bean id="callCxfService" class="com.zaife.struts2.CallCxfService">  
          28.         <property name="client" ref="client" />  
          29.     bean>  
          30.          
          31. beans>  

          Struts配置文件

          1. xml version="1.0" encoding="UTF-8" ?>  
          2.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
          3.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
          4. <struts>  
          5.     <constant name="struts.objectFactory" value="spring" />  
          6.     <constant name="struts.devMode" value="true" />  
          7.   
          8.     <package name="cxf-spring" extends="struts-default">  
          9.   
          10.         <action name="hello" method="execute" class="callCxfService">  
          11.             <result>/index.jspresult>  
          12.                
          13.         action>                
          14.     package>  
          15.   
          16. struts>  

          web.xml配置

          xml 代碼
          1. xml version="1.0" encoding="UTF-8"?>  
          2. <web-app version="2.4"    
          3.     xmlns="http://java.sun.com/xml/ns/j2ee"    
          4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
          5.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    
          6.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
          7.                        
          8.     <servlet>  
          9.         <display-name>CXF Servletdisplay-name>  
          10.         <servlet-name>CXFServletservlet-name>  
          11.         <servlet-class>  
          12.             org.apache.cxf.transport.servlet.CXFServlet   
          13.         servlet-class>  
          14.         <load-on-startup>1load-on-startup>  
          15.     servlet>  
          16.   
          17.     <servlet-mapping>  
          18.         <servlet-name>CXFServletservlet-name>  
          19.         <url-pattern>/test/*url-pattern>  
          20.     servlet-mapping>     
          21.          
          22.     <filter>  
          23.         <filter-name>struts2filter-name>  
          24.         <filter-class>  
          25.             org.apache.struts2.dispatcher.FilterDispatcher   
          26.         filter-class>  
          27.     filter>  
          28.   
          29.     <filter-mapping>  
          30.         <filter-name>struts2filter-name>  
          31.         <url-pattern>/*url-pattern>  
          32.     filter-mapping>      
          33.     <context-param>  
          34.         <param-name>contextConfigLocationparam-name>  
          35.         <param-value>WEB-INF/hello.xmlparam-value>  
          36.     context-param>  
          37.   
          38.     <listener>  
          39.         <listener-class>  
          40.             org.springframework.web.context.ContextLoaderListener   
          41.         listener-class>  
          42.     listener>  
          43.   
          44.   
          45.   <welcome-file-list>  
          46.     <welcome-file>index.jspwelcome-file>  
          47.   welcome-file-list>  
          48. web-app>  

          Jsp頁(yè)面

          1. <%@ page language="java"  pageEncoding="ISO-8859-1"%>  
          2. <%@ taglib prefix="s" uri="/struts-tags" %>  
          3. >  
          4. <html>  
          5.   <head>       
          6.     <title>My JSP 'index.jsp' starting pagetitle>  
          7.       
          8.   head>  
          9.      
          10.   <body>  
          11.     <s:property value="message" /><br>  
          12.   body>  
          13. html>  

          posted on 2007-11-30 16:43 飛雪連天 閱讀(2156) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: cxf+spring+struts2的helloWorld 2016-08-12 13:21 3333

          shenme wanying  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 迁西县| 浏阳市| 香格里拉县| 万州区| 通海县| 寿阳县| 达日县| 虎林市| 日照市| 牟定县| 民权县| 南康市| 南陵县| 淮北市| 巴林右旗| 海伦市| 平泉县| 张北县| 射洪县| 固始县| 扬州市| 塘沽区| 巧家县| 大丰市| 宁城县| 依兰县| 宜君县| 江山市| 高陵县| 柳林县| 东台市| 沂南县| 康定县| 静宁县| 巴林左旗| 漠河县| 张家口市| 宁国市| 南安市| 当涂县| 双城市|