Is It Possible To Spring Autowire the same Instance of a protoype scoped class in two places

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-02-03T13:30:59Z Indexed on 2010/05/19 9:10 UTC
Read the original article Hit count: 284

Hi

** changed the example to better express the situation

i am using spring 2.5 and have the following situation

@Component
@Scope("prototype") 
Class Foo
{
}

class A
{ 
  @Autowired 
  Foo fooA;
}


class B
{ 
  @Autowired 
  Foo fooB;
}



class C
{ 
  @Autowired 
  Foo fooC;
}

i am trying to understand if there is some way to use @Autowired and bind the same instance of FOO onto fooA and fooB while binding a different instance to fooC

i understand that if the scope of FOO will be singleton it will work

but i am wandering if there is a way to achieve the same goal while using a protoype scope.

also please explain is this the correct usage of the autowiring concept ? am i trying to abuse the spring framework purpose

© Stack Overflow or respective owner

Related posts about spring

Related posts about inversion-of-control