1. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>DOCWS</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置beans.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext.xml</param-value>
</context-param>
<!--
应用启动的一个监听器
-->
<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>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
2. applicationContext.xml
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引cxf的一些核心配置 -->
<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" />
<!-- 设置需要进行Spring注解扫描的类包 -->
<context:component-scan base-package="com.wisdom" />
<!-- hibernate与spring整合配置 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/config/jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxActive" value="100" />
<property name="minIdle" value="0" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.DB2Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.connection.SetBigStringTryClob">
true
</prop>
</props>
</property>
</bean>
<bean id="docDaoImpl" class="com.wisdom.dao.impl.DocDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="docServiceImpl" class="com.wisdom.service.impl.DocServiceImpl">
<property name="docDao" ref="docDaoImpl" />
</bean>
<!-- webservice发布路径 -->
<jaxws:server id="docWS" serviceClass="com.wisdom.service.DocService" address="/queryDocByItemId">
<jaxws:serviceBean>
<ref bean="docServiceImpl" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
3. MANIFEST.MF
Manifest-Version: 1.0
Class-Path:
DisableIBMJAXWSEngine: true 解决websphere 7.0不兼容cxf框架
4.service接口
package com.wisdom.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import com.wisdom.model.DocInfo;
@WebService
@SOAPBinding(style=Style.RPC)
public interface DocService {
/**
* 根据巡检单查询文档
* @param itemId 巡检单id
* @return
*/
@WebMethod
public DocInfo queryDocByItemId(@WebParam(name="itemId") String itemId); // @WebParam(name="itemId") 请求的参数
5. webservice接口实现类
package com.wisdom.service.impl;import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import com.wisdom.dao.DocDao;
import com.wisdom.model.DocInfo;
import com.wisdom.service.DocService;
@WebService
@SOAPBinding(style=Style.RPC)
public class DocServiceImpl implements DocService {
private DocDao docDao;
@Override
public DocInfo queryDocByItemId(String itemId) {
return docDao.queryDocByItemId(itemId);
}
public DocDao getDocDao() {
return docDao;
}
public void setDocDao(DocDao docDao) {
this.docDao = docDao;
}
}