CXF - getting started
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CXF - getting started相关的知识,希望对你有一定的参考价值。
<?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:beans="http://cxf.apache.org/configuration/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:core="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/configuration/beans http://cxf.apache.org/schemas/configuration/cxf-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <jaxws:endpoint id="helloWorld1" implementor="idv.steven.cxf.helloworld.HelloWorldImpl" address="http://localhost:9000/CXF/HelloWorld" /> <jaxws:client id="client" serviceClass="idv.steven.cxf.helloworld.HelloWorld" address="http://localhost:9000/CXF/HelloWorld" /> </beans>
<?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:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd" > <context:component-scan base-package="idv.steven.mvc.controller" /> <mvc:annotation-driven /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/jsp/" p:suffix=".jsp" /> </beans>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>CXF</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:beans-config.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
package idv.steven.cxf.helloworld; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHello(@WebParam(name="text") String text); }
package idv.steven.cxf.helloworld; import javax.jws.WebParam; import javax.jws.WebService; @WebService(serviceName = "HelloWorld") public class HelloWorldImpl implements HelloWorld { @Override public String sayHello(@WebParam(name="text") String text) { System.out.println("sayHello called"); return "Hello " + text + "!"; } }
package idv.steven.mvc.controller; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import idv.steven.cxf.helloworld.HelloWorld; @Controller public class SayHelloController { @Autowired private HelloWorld client; @RequestMapping(value="/say", method=RequestMethod.GET) public @ResponseBody Map<String, Object> getHelloWorld(String name) { Map<String, Object> result = new HashMap<String, Object>(); String respText = client.sayHello(name); result.put("result", respText); return result; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.0.0.min.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>SayHello</title> <script type="text/javascript"> var message; $(function() { $("#say").bind("click", function(e) { var myUrl = "<%=request.getContextPath()%>/say.do?name=" + $(‘#name‘).val(); $.ajax({ type: ‘get‘, url: myUrl, dataType: ‘json‘, success: function(data, result) { alert(data.result); }, error: function() { alert(‘error‘); } }); }); }); </script> </head> <body> <form id="helloForm" name="helloForm" method="post"> Name: <input type="text" id="name" name="name" /> <input type="button" id="say" name="say" value="哈囉"/> </form> </body> </html>
以上是关于CXF - getting started的主要内容,如果未能解决你的问题,请参考以下文章
Getting started with Processing 示例11-9 追随鼠标移动
java中使用cxf 发布webservice 成功发布但无法访问
httpd Server not started: (13)Permission denied: make_sock: could not bind to address [::]:8888(代码片段
RuntimeError: An attempt has been made to start a new process before the current process has...(代码片段