You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by aseem cheema <as...@gmail.com> on 2009/04/04 06:39:34 UTC

Retrieving spring beans

Hey Folks,
I am using Spring with cxf, following the sample in
apache-cxf-2.2\samples\java_first_spring_support.

I have some other beans (my application related beans) that are
defined in the same xml file as my endpoint. I need to retrieve these
beans in my service implementation code. I am not able to find an
example of that. How do I do this?

Any help on this will be highly appreciated.
Thanks
-- 
Aseem

Re: Retrieving spring beans

Posted by aseem cheema <as...@gmail.com>.
Works beautifully and its so clean. Thanks Ian.
Aseem

On Sat, Apr 4, 2009 at 3:20 AM, Ian Roberts <i....@dcs.shef.ac.uk> wrote:
> aseem cheema wrote:
>> Hey Folks,
>> I am using Spring with cxf, following the sample in
>> apache-cxf-2.2\samples\java_first_spring_support.
>>
>> I have some other beans (my application related beans) that are
>> defined in the same xml file as my endpoint. I need to retrieve these
>> beans in my service implementation code. I am not able to find an
>> example of that. How do I do this?
>
> The best approach would be to define your implementation bean separately
> from the endpoint, i.e. instead of:
>
> <jaxws:endpoint implementor="my.service.FooImpl" .... />
>
> you do:
>
> <jaxws:endpoint implementor="#serviceImplementation"
>                implementorClass="my.service.FooImpl" .... />
>
> and then you can add the relevant setter methods to your implementation
> class and do dependency injection in the normal Spring way:
>
> <bean id="serviceImplementation" class="my.service.FooImpl">
>  <property name="helper" ref="helperBean" />
>  ...
> </bean>
>
> Ian
>
> --
> Ian Roberts               | Department of Computer Science
> i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK
>



-- 
Aseem

Re: Retrieving spring beans

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
aseem cheema wrote:
> Hey Folks,
> I am using Spring with cxf, following the sample in
> apache-cxf-2.2\samples\java_first_spring_support.
> 
> I have some other beans (my application related beans) that are
> defined in the same xml file as my endpoint. I need to retrieve these
> beans in my service implementation code. I am not able to find an
> example of that. How do I do this?

The best approach would be to define your implementation bean separately
from the endpoint, i.e. instead of:

<jaxws:endpoint implementor="my.service.FooImpl" .... />

you do:

<jaxws:endpoint implementor="#serviceImplementation"
                implementorClass="my.service.FooImpl" .... />

and then you can add the relevant setter methods to your implementation
class and do dependency injection in the normal Spring way:

<bean id="serviceImplementation" class="my.service.FooImpl">
  <property name="helper" ref="helperBean" />
  ...
</bean>

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK