English 中文(简体)
Getting access to a spring bean from a webservice?
原标题:

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

最佳回答

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)

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签