views:

487

answers:

2

I've noticed recently that spring can wire up my ejb's for me if I annotate the ejb with @Interceptors(SpringBeanAutowiringInterceptor.class). I've never actually done this so don't know the details.

I was wondering, is there a way to get this to work with other kinds of beans, for example, @WebService annotated ones as well.

At the moment in my web service classes (because the application server manages them) I have to load the dependencies from the BeanFactory and would thus prefer to have them autowired.

I know I could use the @Configurable annotation but am not particularly keen to have to specify and agent on the VM.

Is this possible?

+1  A: 

Yes, of course. There's @WebService, @Repository, @Controller, @Service, @Endpoint, and other annotations in Spring. Here's an example.

duffymo
Fully aware of @Repository and the others (they come from spring), but am wondering if spring will be able to autowire onto objects the application server created (@WebService annotation)?
Michael Wiles
A: 

Once again, spring has thought of this use case and catered for it!

The problem is that @WebService is not a spring annotation, it is a JAX-WS annotation and thus classes that are annotated with @WebService to be exposed as web services are not managed by spring, but their life cycle is managed by JAX-WS.

The way to handle this case is to have the JAX-WS managed bean extend org.springframework.web.context.support.SpringBeanAutowiringSupport - this will enable the @Autowire annotation, for example, to work in this bean. see here for more information

Michael Wiles