dimarts, 5 de juliol de 2011

Creating Spring web services using annotations

In this entry, I'm about to show how easy it is to create a web service using Spring-WS using annotations. Spring-WS makes it very easy to publish webservices so that you can publish your already existing services. It is based on JAX-WS, so it is great for application servers like Weblogic, since it uses the same web service technology stack.

To create a Spring-WS based web service, we just need to implement one class: the endpoint. By the way, since we are using Spring, usually it'd be better to implement the logic for the web service in its own service class, so that's the way we're going to take...

To create the enpoint class we just need to create a class extending org.springframework.web.context.support.SpringBeanAutowiringSupport and annotated by javax.jws.WebService. Once we have this class, any method representing an operation in the service, will have to be annotated by javax.jws.WebMethod.

Supose we want to publish a web service called GreetingsService with an operation sayHi. In this case, we'd create the following endpoint class:

10:37:44.788 [main] DEBUG org.springframework.web.context.support.SpringBeanAutowiringSupport - Current WebApplicationContext is not available for processing of : Make sure this class gets constructed in a Spring web application. Proceeding without injection.

About me

I'm currently working as a JEE architect and Liferay specialist in Barcelona. I started this blog just to try to give something back to the community, that has helped me so much along all this years...

Along my entries you'll find some sample code, feel free to use it, just remember to put a link to this blog wherever you use it, please.

You can find me at aigloss@gmail.com or aigloss@hotmail.com, or via linkedIn.