从 web 服务访问 spring bean?

发布于 2024-08-13 06:28:53 字数 240 浏览 5 评论 0原文

我在我的 cxf.xml 文件中创建了一个 cxf web 服务,我有以下标签。 bean id="videoStatsTable" class="com.company.auth.dataobjects.VideoStatsTable"

根据我的理解,Spring 应该为我创建这个对象。问题是我不知道如何访问它。似乎我需要 servletContext,但由于我不在 servlet 中,我在 WS 中,所以不知道该怎么做?

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?

W

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭⌒浅淡时光〆 2024-08-20 06:28:53

Spring 有一种声明 Web 服务的简化方法(使用 cxf)。

在您的 applicationContext.xml 中添加 xmlns:jaxws="http://cxf.apache.org/jaxws" 到您的根标记 (< /code>) 并

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 的映射)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文