Spring Framework - keshavbaweja-git/guides GitHub Wiki
Inversion Of Control
- Spring Framework implements Inversion of Control (IoC) for dependency management. Spring implementation of IoC is based on Dependency Injection where in an object specifies its dependencies as constructor arguments or properties. The object does not instantiate these dependencies, instead the Spring IoC container instantiates the dependencies and injects them into the object.
BeanFactory
provides core capabilities required for Dependency Injection
ApplicationContext
is a superset of BeanFactory
and provides additional enterprise features.
ApplicationContext
is responsible for instantiating, configuring and assembling the beans.
- Configuration metadata for beans can be specified as xml, annotations or Java code.
Bean Scopes
- Singleton (default) (should be used with stateless beans)
- Prototype (should be used with stateful beans)
- Spring does not manage the complete lifecycle of a prototype bean. The container instantiates, configures, and otherwise assembles a prototype object and hands it to the client, with no further record of that prototype instance. Thus, although initialization lifecycle callback methods are called on all objects regardless of scope, in the case of prototypes, configured destruction lifecycle callbacks are not called. The client code must clean up prototype-scoped objects and release expensive resources that the prototype beans hold. To get the Spring container to release resources held by prototype-scoped beans, try using a custom bean post-processor, which holds a reference to beans that need to be cleaned up.
- Request (HTTP request)
- Session (HTTP Session)
- Application (ServletContext)
- Websocket
Application Events
- Event handling in the ApplicationContext is provided through the ApplicationEvent class and the ApplicationListener interface.
- If a bean that implements the ApplicationListener interface is deployed into the context, every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified.
- Essentially, this is the standard Observer design pattern.
- Application events mechanism in Spring framework has support for
- Custom events
- Transaction bound events
- Generics support
- Annotation based event listener
- Reference
Spring Boot Actuator
management:
health:
ldap:
enabled: false
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
Spring Boot Console Appender
logging:
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{userId}] [%X{correlationId}] %5p --- [%t] %-40.40logger{39} : %m%n%wEx"