server端
beans.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!--*******************Hibernate数据库持久层配置文件***********************-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${hibernate.connection.driver_class}" />
<property name="url" value="${ hibernate.connection.url}" />
<property name="username" value="${ hibernate.connection .username}" />
<property name="password" value="${ hibernate.connection .password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.use_sql_comments">
${hibernate.use_sql_comments}
</prop>
<prop key="hibernate.format_sql">
${hibernate.format_sql}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">
${hibernate.bytecode.use_reflection_optimizer}
</prop>
<prop key="hibernate.jdbc.fetch_size">
${hibernate.jdbc.fetch_size}
</prop>
<prop key="hibernate.jdbc.batch_size">
${hibernate.jdbc.batch_size}
</prop>
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/ws/pojo/</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dao" class="ws.dao.HibernateDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- SurveyService -->
<bean id="customerService" class="ws.service.CustomerServiceImpl">
<property name="dao" ref="dao" />
</bean>
</beans>
webservices.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import Apache CXF Bean Definition -->
<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"/>
<!-- Expose SurveyWebService -->
<jaxws:server id="customerWService"
serviceClass="ws.service.ICustomerService"
address="/CustomerService">
<jaxws:serviceBean>
<ref bean="customerService"/> <!-- 要暴露的 bean 的引用 -->
</jaxws:serviceBean>
</jaxws:server>
</beans>
要注意bean的id,address 和server的id
然后编写接口,跟其他spring+hibernate写法一样
部署到webserver上
最后生成客户端
wsdl2java -p ws.client -d C:/Java/CXF/bin/source -verbose http://localhost:8080/ws/CustomerService?wsdl
客户端的beans.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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import Apache CXF Bean Definition -->
<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"/>
<!-- Client -->
<jaxws:client id="customerServiceClient"
serviceClass="ws.client.ICustomerService"
address="http://localhost:8080/ws/CustomerService"/>
</beans>
取出customerServiceClient,也可以通过注入取出
// 加载客户端的配置定义
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
// 获取定义的 Web Service Bean
ICustomerService customerService = (ICustomerService) context.getBean("customerServiceClient");