I\'m learning Spring 3 and I don\'t seem to grasp the functionality behind
and
.
Spring allows you to do two things:
1. Autowiring
Usually in applicationContext.xml you define beans and other beans are wired using
constructor or setter methods. You can wire beans using XML or annotations.
In case you use annotations, you need to activate annotations and you have to add
in applicationContext.xml. This will simplify the
structure of the tag from applicationContext.xml, because you will not have to manually wire beans (constructor or setter). You can use @Autowire
annotation and the beans will be wired by type.
A step forward for escaping the manual XML configuration is
2. Autodiscovery
Autodiscovery is simplifying the XML one step further, in the sense that you don't even need too add the
tag in applicationContext.xml. You just mark the specific beans with one of the following annotation and Spring will automatically wire the marked beans and their dependencies into the Spring container. The annotations are as follow: @Controller, @Service, @Component, @Repository. By using
and pointing the base package, Spring will auto-discover and wire the components into Spring container.
As a conclusion:
is used in order to be able to use
@Autowired annotation
is used to determine the search of
specific beans and attempt of autowiring.