2009-12-01 98 views
1

我在我的cxf.xml文件中創建了一個cxf webservice我有以下標記。 bean id =「videoStatsTable」class =「com.company.auth.dataobjects.VideoStatsTable」從webservice訪問Spring bean?

根據我的理解,Spring應該爲我創建這個對象。問題是我不確定如何訪問它。看起來好像我需要servletContext,但因爲我不在一個WS中的servlet im,我不知道該怎麼做?

W

回答

2

Spring有一個簡單的聲明Web服務(用cxf)的方法。

<!-- Loading CXF modules --> 
<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" /> 

最後聲明你的WebService實現:

applicationContext.xml添加 xmlns:jaxws="http://cxf.apache.org/jaxws"到您的根標籤( <beans>)和

http://cxf.apache.org/core 
     http://cxf.apache.org/schemas/core.xsd 
     http://cxf.apache.org/jaxws 
     http://cxf.apache.org/schemas/jaxws.xsd 

schemaLocation

然後加入

<jaxws:endpoint id="MyWebService" implementor="#MyWebServiceImpl" 
    address="/myWebServiceAddress" /> 

其中#MyWebServiceImpl是您的bean的ID。您可以隨意將任何其他彈簧依賴關係注入到該bean中。

然後web服務將通過http://yourhost/cxfuri/myWebServiceAddress(其中cxfuri是您的CXF Servlet的映射)可訪問