从Web服务访问spring bean?

时间:2009-12-01 15:49:08

标签: spring cxf javabeans

我在cxf.xml文件中创建了一个cxf webservice,我有以下标记。  bean id =“videoStatsTable”class =“com.company.auth.dataobjects.VideoStatsTable”

据我所知,Spring应该为我创建这个对象。问题是我不知道如何访问它。好像我需要servletContext,但因为我不是在WS中的一个servlet,我不知道怎么做?

w ^

1 个答案:

答案 0 :(得分:2)

Spring有一种简单的方式来声明Web服务(使用cxf)。

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

然后添加:

<!-- 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实现:

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

其中#MyWebServiceImpl是您的bean的ID。您可以自由地将任何其他spring依赖项注入该bean。

然后可以通过http://yourhost/cxfuri/myWebServiceAddress访问Web服务(其中cxfuri是您的CXF Servlet的映射)

相关问题