首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

CXF+Spring+Tomcat精简示例

2013-11-02 
CXF+Spring+Tomcat简明示例如上图所示,全部依赖的第三方库都在lib中,下面贴出全部代码。IHelloService.java

CXF+Spring+Tomcat简明示例


如上图所示,全部依赖的第三方库都在lib中,下面贴出全部代码。
IHelloService.java

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例package bing.server;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例import javax.jws.WebService;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例/** *//**
CXF+Spring+Tomcat精简示例 * <p>
CXF+Spring+Tomcat精简示例 * WebService接口
CXF+Spring+Tomcat精简示例 * </p>
CXF+Spring+Tomcat精简示例 *
CXF+Spring+Tomcat精简示例 * @author IceWee
CXF+Spring+Tomcat精简示例 * @date 2012-7-6
CXF+Spring+Tomcat精简示例 * @version 1.0
CXF+Spring+Tomcat精简示例*/
CXF+Spring+Tomcat精简示例@WebService
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例publicinterface IHelloService CXF+Spring+Tomcat精简示例{
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例??? public String sayHello(String username);
CXF+Spring+Tomcat精简示例???
CXF+Spring+Tomcat精简示例}
CXF+Spring+Tomcat精简示例


HelloServiceImpl.java

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例package bing.server;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例import javax.jws.WebService;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例/** *//**
CXF+Spring+Tomcat精简示例 * <p>
CXF+Spring+Tomcat精简示例 * WebService实现类
CXF+Spring+Tomcat精简示例 * </p>
CXF+Spring+Tomcat精简示例 *
CXF+Spring+Tomcat精简示例 * @author IceWee
CXF+Spring+Tomcat精简示例 * @date 2012-7-6
CXF+Spring+Tomcat精简示例 * @version 1.0
CXF+Spring+Tomcat精简示例*/
CXF+Spring+Tomcat精简示例@WebService(endpointInterface ="bing.server.IHelloService", serviceName ="HelloService")
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例publicclass HelloServiceImpl implements IHelloService CXF+Spring+Tomcat精简示例{
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例??? @Override
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例??? public String sayHello(String username) CXF+Spring+Tomcat精简示例{
CXF+Spring+Tomcat精简示例??????? return"hello, "+ username;
CXF+Spring+Tomcat精简示例??? }
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例}
CXF+Spring+Tomcat精简示例


HelloServiceClient.java

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例package bing.client;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例import org.springframework.context.ApplicationContext;
CXF+Spring+Tomcat精简示例import org.springframework.context.support.ClassPathXmlApplicationContext;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例import bing.server.IHelloService;
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例/** *//**
CXF+Spring+Tomcat精简示例 * <p>
CXF+Spring+Tomcat精简示例 * WebService调用方-客户端
CXF+Spring+Tomcat精简示例 * </p>
CXF+Spring+Tomcat精简示例 *
CXF+Spring+Tomcat精简示例 * @author IceWee
CXF+Spring+Tomcat精简示例 * @date 2012-7-6
CXF+Spring+Tomcat精简示例 * @version 1.0
CXF+Spring+Tomcat精简示例*/
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例publicclass HelloServiceClient CXF+Spring+Tomcat精简示例{
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例CXF+Spring+Tomcat精简示例??? publicstaticvoid main(String[] args) CXF+Spring+Tomcat精简示例{
CXF+Spring+Tomcat精简示例??????? ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext-client.xml");
CXF+Spring+Tomcat精简示例??????? IHelloService helloService = (IHelloService) context.getBean("client");
CXF+Spring+Tomcat精简示例??????? String response = helloService.sayHello("Peter");
CXF+Spring+Tomcat精简示例??????? System.out.println(response);
CXF+Spring+Tomcat精简示例??? }
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例}
CXF+Spring+Tomcat精简示例


applicationContext-server.xml

?

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例<?xml version="1.0" encoding="UTF-8"?>
CXF+Spring+Tomcat精简示例<beans xmlns="http://www.springframework.org/schema/beans"
CXF+Spring+Tomcat精简示例??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
CXF+Spring+Tomcat精简示例??? xmlns:jaxws="http://cxf.apache.org/jaxws"
CXF+Spring+Tomcat精简示例??? xsi:schemaLocation="http://www.springframework.org/schema/beans
CXF+Spring+Tomcat精简示例?????????????????????? http://www.springframework.org/schema/beans/spring-beans.xsd
CXF+Spring+Tomcat精简示例?????????????????????? http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
CXF+Spring+Tomcat精简示例??? <!--
CXF+Spring+Tomcat精简示例??????? ***注意***
CXF+Spring+Tomcat精简示例??????? 手动添加的内容:
CXF+Spring+Tomcat精简示例??????? xmlns:jaxws="http://cxf.apache.org/jaxws"
CXF+Spring+Tomcat精简示例??????? http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
CXF+Spring+Tomcat精简示例???? -->
CXF+Spring+Tomcat精简示例???
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf.xml"/>
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例??? <jaxws:endpoint id="helloService" implementor="bing.server.HelloServiceImpl" address="/helloService"/>
CXF+Spring+Tomcat精简示例???????
CXF+Spring+Tomcat精简示例</beans>
CXF+Spring+Tomcat精简示例


applicationContext-client.xml

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例<?xml version="1.0" encoding="UTF-8"?>
CXF+Spring+Tomcat精简示例<beans xmlns="http://www.springframework.org/schema/beans"
CXF+Spring+Tomcat精简示例??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
CXF+Spring+Tomcat精简示例??? xmlns:jaxws="http://cxf.apache.org/jaxws"
CXF+Spring+Tomcat精简示例??? xsi:schemaLocation="http://www.springframework.org/schema/beans
CXF+Spring+Tomcat精简示例?????????????????????? http://www.springframework.org/schema/beans/spring-beans.xsd
CXF+Spring+Tomcat精简示例?????????????????????? http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
CXF+Spring+Tomcat精简示例??? <!--
CXF+Spring+Tomcat精简示例??????? ***注意***
CXF+Spring+Tomcat精简示例??????? 手动添加的内容:
CXF+Spring+Tomcat精简示例??????? xmlns:jaxws="http://cxf.apache.org/jaxws"
CXF+Spring+Tomcat精简示例??????? http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
CXF+Spring+Tomcat精简示例???? -->
CXF+Spring+Tomcat精简示例???
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf.xml"/>
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
CXF+Spring+Tomcat精简示例??? <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例??? <bean id="client" class="bing.server.IHelloService" factory-bean="clientFactory" factory-method="create"/>
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例??? <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
CXF+Spring+Tomcat精简示例??????? <property name="serviceClass" value="bing.server.IHelloService"/>
CXF+Spring+Tomcat精简示例??????? <property name="address" value="http://localhost:8080/CXFDemo/ws/helloService"/>
CXF+Spring+Tomcat精简示例??? </bean>
CXF+Spring+Tomcat精简示例</beans>
CXF+Spring+Tomcat精简示例


web.xml

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->CXF+Spring+Tomcat精简示例<?xml version="1.0" encoding="UTF-8"?>
CXF+Spring+Tomcat精简示例<web-app version="3.0"
CXF+Spring+Tomcat精简示例??? xmlns="http://java.sun.com/xml/ns/javaee"
CXF+Spring+Tomcat精简示例??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
CXF+Spring+Tomcat精简示例??? xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
CXF+Spring+Tomcat精简示例??? http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
CXF+Spring+Tomcat精简示例? <display-name>CXFDemo</display-name>
CXF+Spring+Tomcat精简示例?
CXF+Spring+Tomcat精简示例? <context-param>
CXF+Spring+Tomcat精简示例????? <param-name>contextConfigLocation</param-name>
CXF+Spring+Tomcat精简示例????? <param-value>classpath:applicationContext-server.xml</param-value>
CXF+Spring+Tomcat精简示例? </context-param>
CXF+Spring+Tomcat精简示例
CXF+Spring+Tomcat精简示例? <listener>
CXF+Spring+Tomcat精简示例??? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
CXF+Spring+Tomcat精简示例? </listener>
CXF+Spring+Tomcat精简示例?
CXF+Spring+Tomcat精简示例? <servlet>
CXF+Spring+Tomcat精简示例??? <servlet-name>CXFServlet</servlet-name>
CXF+Spring+Tomcat精简示例??? <display-name>CXFServlet</display-name>
CXF+Spring+Tomcat精简示例??? <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
CXF+Spring+Tomcat精简示例??? <load-on-startup>1</load-on-startup>
CXF+Spring+Tomcat精简示例? </servlet>
CXF+Spring+Tomcat精简示例? <servlet-mapping>
CXF+Spring+Tomcat精简示例??? <servlet-name>CXFServlet</servlet-name>
CXF+Spring+Tomcat精简示例??? <url-pattern>/ws/*</url-pattern>
CXF+Spring+Tomcat精简示例? </servlet-mapping>
CXF+Spring+Tomcat精简示例? <welcome-file-list>
CXF+Spring+Tomcat精简示例??? <welcome-file>index.jsp</welcome-file>
CXF+Spring+Tomcat精简示例? </welcome-file-list>
CXF+Spring+Tomcat精简示例</web-app>
CXF+Spring+Tomcat精简示例


所有项目都已配置完成,可以发布到Tomcat了,在浏览器中输入:http://localhost:8080/CXFDemo/ws,返回如图:
CXF+Spring+Tomcat精简示例

从上图中可以看到我们对外发布的WebService接口,点击蓝色超链接,返回如图:
CXF+Spring+Tomcat精简示例
到此,证明我们的Web Service已经发布成功,可以进行调用测试了。运行HelloServiceClient,返回如图:
CXF+Spring+Tomcat精简示例

全文完!

转载于:http://www.blogjava.net/icewee/archive/2012/07/06/382399.html

热点排行