Using Spring 2.5 Auto Detection of Components
Spring 2.5 has some great improvements that make configuration much simpler. One that I very much like is the auto detection of components in the classpath. The Spring 2.5 documentation on this subject is worth reading. It also gives a nice and simple example.
For the 2.0 branch of the Polar Rose Web Service Foundation I have added an AnnotationWebServiceController that uses this new Spring 2.5 functionality.
This makes creating a web service very very simple. All you have to do to get going with a public web service is annotate your Actions with @WebServiceAction and tell Spring to scan for component.
This is an example action:
package com.foo.action. @WebServiceAction(name = "Hello", version = "2008-04-01") public class HelloAction implements WebServiceActionHandler{ public Object execute(WebServiceActionContext context, Parameters parameters) throws ActionHandlerException { return “Hello, ” + parameters.getName(); } public static class Parameters { private String name; public String getName() { return name; } @WebServiceParameter public void setName(String name) { this.name = name; } } }
The following Spring configuration is enough to setup the web service controller:
<beans ...>
<context:component-scan base-package="com.foo.action"/>
<bean id="annotationWebServiceController" class="com.polarrose.wsf.controller.AnnotationWebServiceController">
<property name="version" value="2008-04-01"/>
</bean>
</beans>
I think this is a really nice way to auto-detect and configure ‘top level’ components. It removes a lot of XML configuration. Which I don’t mind, but less is always better.
If you want to play with the framework, you can check it out from Google Code.
Modified