Spring 2 Flashcards
when are annotations processed?
compile or runtime.
why use annotations?
XML config can be very verbose. Annotations allow you to minimize the xml configuration.
how do annotations work?
when you add annotations to a class, spring will scan your classes for special annotations. when it finds one, it will automatically register that bean with the spring container.
what is autowiring?
Autowiring feature of spring framework enables you to inject the object dependency implicitly. You can use the annotation on setter methods to get rid of the element in XML configuration file.
types of autowiring
- constructor injection
- setter injection
- field injections
field injection development process
Configure the dependency injection with the @Autowired annotation (applied directly to the field and you do not need setter methods).
specify bean scope annotation
@Scope(“singleton”)
annotations for bean init & best destruction
@PostConstruct & @PreDestroy
development process for bean init & best destruction
- define methods for init & destroy
- add the @PreDestroy & @PostConstruct annotations