Inversión de control
"No nos llames, nosotros te llamamos"
¿Qué aspecto se invierte?
Diferencia entre framework y librería
Martin Fowler: "Inyección de dependencias"
Inyección de dependencias
Definición más específica de Inversión de Control
Los objetos son configurados por una entidad externa
Formas de inyección
Setter injection
Constructor injection
Constructor Argument Type Matching
Constructor Argument Index
Method injection
Configuración
Straight values (primitives, Strings, etc.)
References to other beans (collaborators)
Inner beans
Siempre son prototypes
Collections
list
set
map
props
Spring IoC Container
Spring IoC Container
Bean Factory
Responsable de instanciar, configurar e inyectar las dependencias
Varias implementaciones: XMLBeanFactory
ApplicationContext
Hereda de BeanFactory
Funcionalidades
Integración con AOP
Internacionalización
ResourceBundleMessageSource
ReloadableResourceBundleMessageSource
Event propagation
ApplicationEvent
ContextRefreshedEvent
ContextStartedEvent
ContextStoppedEvent
ContextClosedEvent
RequestHandledEvent
ApplicationListener
WebApplicationContext
Aplicaciones web
ContextLoaderListener
Beans
Attributes
class
name
constructor-args
properties
lazy initialization
inicialization method
destruction method
autowiring
Las configuraciones explícitas sobrescriben el autowiring
Modos
no
byName
byType
constructor
autodetect
dependency checking
Modos
none
simple
object
all
@Required
scope
Tipos
singleton
prototype
request
session
global session
Solo en Contexto Web
Scoped beans como dependencias
<aop:scoped-proxy/>
Custom scopes
Lifecycle
Características avanzadas
Component autoscan
context:component-scan
@Component
@Controller
@Service
@Repository
Custom stereotypes
Autowiring
@Autowired
Autowiring por tipo
@Qualifier
Custom qualifier annotations
Anotaciones JSR-250
@Resource
Autowiring por nombre
Initialization and destruction callbacks
@PreDestroy
@PostConstruct
Acerca de
Topic
Topic