CXF:将spring bean 注入到 jaxws:endpoin中去

本文介绍如何在Spring环境中配置WebService并实现与数据库交互。通过配置applicationContext.xml文件,完成数据库连接设置及WebService接口部署。具体包括使用Hibernate进行数据操作,并通过CXF实现WebService服务发布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在webService中需要用spring容器中的资源来实现功能,如需要获取数据库连接

applicationContext.xml配置文件:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx" 
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jaxws="http://cxf.apache.org/jaxws" 
	xmlns:jaxrs="http://cxf.apache.org/jaxrs"
	xsi:schemaLocation="
		   http://www.springframework.org/schema/beans 
		   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		   http://www.springframework.org/schema/tx 
		   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
		   http://www.springframework.org/schema/aop 
		   http://www.springframework.org/schema/aop/spring-aop-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 
		   http://cxf.apache.org/jaxrs 
		   http://cxf.apache.org/schemas/jaxrs.xsd"> 

    <!-- 数据库连接配置 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
............................<!-- 省略 -->
    </bean>

      <!-- 配置 webservice 接口 -->
    <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" /> 
      
      <bean id="imple" class="com.asdc.webService.servers.Imple">
          <property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      <jaxws:endpoint id="url" address="/urlImple">
          <jaxws:implementor ref="imple"></jaxws:implementor>
      </jaxws:endpoint>
</beans>
这样在Impl,java文件中可以直接定义SessionFactory 类型和使用setSessionFactory 方法了。

关于下面的配置:

     <bean id="imple" class="com.asdc.webService.servers.Imple">
          <property name="sessionFactory" ref="sessionFactory"></property>
      </bean>
      <jaxws:endpoint id="url" address="/urlImple">
          <jaxws:implementor ref="imple"></jaxws:implementor>
      </jaxws:endpoint>
暂时先用这一种,以后用时间在试试其他的配置方式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值