CXF+spring+hibernate

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");



 

 

 

 

转载于:https://my.oschina.net/u/104203/blog/41196

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值