xfire1.2.6建立webservice发布接口1(server端配置及查看发布状态)

环境:jdk6 , xfire1.2.6 , Struts1.1(公司的老版本) , Hibernate3.3.1 , Spring2.0.2 ,  Ext2.1  ,由于这是拿回家做得,所以引入的都是MyEclipse8.5中xfire的包(xfire版本也是1.2.6,其他地方可能有所不同)

由于之前已经把Ext + SSH的项目写好了,这篇笔记只针对xfire的配置和WebService的发布,关于客户端的测试类将会在下篇(xfire1.2.6建立webservice发布接口2(client)中记录

重点配置:(借鉴公司项目的配置)

1.web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 4   id="WebApp_ID"
 5   version="3.0">
 6   <description>ExtMyEclipse</description>
 7   <display-name>Ext Demo</display-name>
 8 
 9 <!-- contextConfigLocation beans.xml位于src下 -->
10       <context-param>
11         <param-name>contextConfigLocation</param-name>
12         <param-value>
13             classpath:/beans.xml
14         </param-value>
15     </context-param>
16   
17 
18 <!-- Spring Listener -->  
19   <listener>
20   <listener-class>
21    org.springframework.web.context.ContextLoaderListener
22   </listener-class>
23   </listener>
24 
25 <!-- XFire WebServic 分发请求,遇到webservice请求提交到指定servlet接收处理-->
26     <servlet>
27         <servlet-name>xfire</servlet-name>
28         <servlet-class>
29             org.springframework.web.servlet.DispatcherServlet
30         </servlet-class>
31     </servlet>
32     <servlet>
33         <servlet-name>xfireServlet</servlet-name>
34         <servlet-class>
35             org.codehaus.xfire.spring.XFireSpringServlet
36         </servlet-class>
37     </servlet>
38     
39 <!-- xfire mapping -->
40     <servlet-mapping>
41         <servlet-name>xfire</servlet-name>
42         <url-pattern>*.ws</url-pattern>
43     </servlet-mapping>
44     <servlet-mapping>
45         <servlet-name>xfireServlet</servlet-name>
46         <!-- URI open Web Service -->
47         <url-pattern>/service/*</url-pattern>
48     </servlet-mapping>
49     
50 <!-- Struts1.1 cfg -->
51   <servlet>
52     <servlet-name>action</servlet-name>
53     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
54     <init-param>
55       <param-name>config</param-name>
56       <param-value>/WEB-INF/struts-config.xml</param-value>
57     </init-param>
58     <load-on-startup>2</load-on-startup>
59   </servlet>
60   <servlet-mapping>
61     <servlet-name>action</servlet-name>
62     <url-pattern>*.do</url-pattern>
63   </servlet-mapping>
64     
65   <welcome-file-list>
66     <welcome-file>index.jsp</welcome-file>
67   </welcome-file-list>
68 </web-app>

2.beans.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
 5        
 6 <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
 7 <!-- dataSource and sessionFactory -->
 8     <bean id="dataSource"
 9         class="org.springframework.jdbc.datasource.DriverManagerDataSource"
10         destroy-method="close">
11         <property name="driverClassName" value="com.mysql.jdbc.Driver" />
12         <property name="url" value="jdbc:mysql://localhost:3306/credit_report" />
13         <property name="username" value="root" />
14         <property name="password" value="root" />
15     </bean>
16     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
17         <property name="dataSource" ref="dataSource" />
18         <property name="mappingResources">
19                 <list>
20                     <value>com/report/model/Report.hbm.xml</value>
21                 </list>
22         </property>
23         <property name="hibernateProperties">
24             <props>
25                 <prop key="hibernate.dialect">
26                     org.hibernate.dialect.MySQLInnoDBDialect
27                 </prop>
28                 <prop key="hibernate.show_sql">
29                     true
30                 </prop>
31                 <prop key="current_session_context_class">
32                     thread
33                 </prop>
34             </props>
35         </property>
36     </bean>
37 <!-- inject "serviceImpl" in Struts1.1 Action -->
38     <bean name="/report" class="com.report.action.ReportAction">
39         <property name="service">
40             <ref bean="reportServiceHibernateImpl" />
41         </property>
42     </bean>
43     
44     
45 <!--XFire WebService 基类-->
46     <bean id="baseWebService"
47         class="org.codehaus.xfire.spring.remoting.XFireExporter"
48         abstract="true">
49         <property name="serviceFactory" ref="xfire.serviceFactory" />
50         <property name="xfire" ref="xfire" />
51     </bean>
52 
53 
54 <!-- service Impl -->
55     <bean id="reportServiceHibernateImpl" class="com.report.service.impl.ReportServiceHibernateImpl">
56        <property name="sessionFactory">
57             <ref bean="sessionFactory" />
58         </property>
59     </bean>
60     
61 
62 
63     
64     
65     <!-- 建立WebService定义 namespace的value是随便写的(无所谓)-->
66     <bean id="ReportService" parent="baseWebService">
67         <property name="namespace" value="http://www.cfcc.com" />
68         <!-- impl -->
69         <property name="serviceBean" ref="reportServiceHibernateImpl" />
70         <!-- interface -->
71         <property name="serviceClass" value="com.report.service.ReportServiceHibernate" />    
72     </bean>
73     
74     
75 </beans>

之前看到过其他教程说要配services.xml.我没配是因为spring结合了xfire,services.xml中的内容其实就是beans.xml中"建立webservice定义"这段的意思!

配置到此结束,只需要把该项目部署到server上然后运行server就可以了,下面要用MyEclipse工具测试时候发布成功,步骤如下:

1,打开MyEclipse的"Launch web service Explorer",弹出浏览器,右侧选择WSDL page,点左侧导航,

2.在主面板的URL中输入http://127.0.0.1:8080/ExtWS/service/ReportServiceHibernate?wsdl,点击"GO",测试发布状态,so easy(要注意url,与配置有关)

IWAB0381I http://127.0.0.1:8080/ExtWS/service/ReportServiceHibernate?wsdl was successfully opened.------------------------正确提示
原文地址:https://www.cnblogs.com/dirkmurphyjava/p/3272417.html