I came into IOC via Google Guice.
And now I've been forced to use Spring 2.5.6 at work & I am lost because Spring is quite complicated. Here are some questions after reading bits of the spring docs:
- What is the difference between
@Service
,@Controller
and@Component
? If I just want to auto wire my objects like Guice, do I need to be bothered by all these stereotypes ? I'm planning to go the component-scan route with only constructor injection (Setter injection is mostly advocated by the Church of Scientology) and no freaking XML shit. So is this code extract all I need ?
@Component public class Foo { @Autowired(required=true) public Foo( Bar bar, @Qualifier("yay") Boo yay, @Qualifier("hoo") Boo hoo ) { _bar = bar; _boo = boo; }
....snipped... } @Component @Qualifier("yay") @Scope(BeanDefinition.SCOPE_PROTOTYPE) public BooYay implements Boo { } @Component @Qualifier("hoo") @Scope(BeanDefinition.SCOPE_PROTOTYPE) public BooHoo implements Boo { }Bar _bar; Boo _boo;
- In the above example, did I correctly qualify the 2 different implementations of
Boo
? - Is there any feature similar to Google Guice's Providers ?
- How do I mimic the
@Singleton
behaviour (in Guice) in Spring ?
- In the above example, did I correctly qualify the 2 different implementations of
Thanks