Webservices 之CXF 小例子

來源:互聯網
上載者:User

標籤:http   io   os   ar   java   sp   檔案   on   art   

第一步:匯入相關jar包

第二步:在介面中進行配置,類中可以不進行配置

package mycompany.webservice.server;import java.util.List;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface Greeting {       public String greeting(String userName);      }
package mycompany.webservice.server;import java.util.Calendar;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import javax.jws.WebService;@WebService(endpointInterface = "mycompany.webservice.server.Greeting")public class GreetingServiceImpl implements Greeting { public String greeting(String userName) {  return "Hello " + userName + ", currentTime is "    + Calendar.getInstance().getTime(); }}

第三步:建立spring。xml進行配置

這三個資源檔必須匯入,否則會報錯<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" /> <bean id="greetingServiceImpl" class="mycompany.webservice.server.GreetingServiceImpl"/><jaxws:endpoint id="greetingService"  implementor="#greetingServiceImpl" address="/Greeting" />註:address可以寫絕對路徑也可以寫相對路徑

第四步:web.xml中位置

spring進行配置<listener>       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>CXF進行配置 <servlet>         <servlet-name>CXFServlet</servlet-name>         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>         <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>          <servlet-name>CXFServlet</servlet-name>  <!--==這個設定很重要,那麼我們的webservice的地址就是http://localhost:8080/yourProgramName/webservice/Greeting===-->        <url-pattern>/webservice/*</url-pattern> </servlet-mapping>

第五步:產生用戶端代碼

在E:\apache-cxf-2.7.7\bin建立bat檔案,內容如下

wsdl2Java -p com.test .svn?wsdl



Webservices 之CXF 小例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.