在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>
暂时先用这一种,以后用时间在试试其他的配置方式。