开发者

Getting access to a spring bean from a webservice?

开发者 https://www.devze.com 2022-12-13 03:12 出处:网络
I have created a cxf webservice within my cxf.xml file I have the following tag. bean id=\"videoStatsTable\" class=\"com.company.auth.dataobjects.VideoStatsTable\"

I have created a cxf webservice within my cxf.xml file I have the following tag. bean id="videoStatsTable" class="com.company.auth.dataobjects.VideoStatsTable"

From what I understand Spring should create this object for me. The problem is I'm not sure how to get access to it. It seems as if I need the servletContext but as I'm in not in a servlet im in a WS im not sure how to do this?

开发者_JS百科

W


Spring has a simplifed way of declaring web services (wiht cxf).

in your applicationContext.xml add xmlns:jaxws="http://cxf.apache.org/jaxws" to your root tag (<beans>) and

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

to your schemaLocation

Then add:

<!-- 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" />

And finally declare your WebService implementation:

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

where #MyWebServiceImpl is the ID of your bean. You can freely inject any other spring dependencies into that bean.

Then the web service will be accessible through http://yourhost/cxfuri/myWebServiceAddress (where cxfuri is the mapping of your CXF Servlet)

0

精彩评论

暂无评论...
验证码 换一张
取 消