- Objects manged by the Spring IoC container.
- Created as per the configuration metadata user provided to the container.
- Describing the objects that need to instantiated and managed by the IOC container.
- Pure XML
- Mention in the XML document to look for annotations
- Pure annotation - @Configuration and @Bean annotations
- Pure XML
Spring Bean Scopes
- Singleton - In an IOC container
- Global Session
Note: Global Session will be coming into picture for portlet applications. In end-user point of view, portlet is a part of web page which receives request, gives response. There can be multiple portlets inside a web application. If we we want to share beans across all these portlets, then we can use global session scoped beans
Dependency Injection (DI)
In case of classess referring to other classess, there is no need for the developer to create the class objects. Instead, need to describe the objects, and which all objects will be having references to other objecs. The bean creation and giving the referred object will be done by the spring IoC contianer.
There are two ways of dependency injection - Setter & Constructor injection.
- IoC container will invoke the class constructor with dependencies.
- Beans will be reinstantiated if any dependency modification happens.
- Partial initialization is not possible.
- Calls the setter methods for the dependency injection after calling no-argment or default constructor
- Override the setter
- Aspect - A module which offers some common functionalities which is separate from the business logic. Logging, authentication, ..etc
- Joint point - A place in the code where aspect can be introduced
- Advice - Actual piece of code that will be executed in join points
- Point cut - Set of one or more joint points where advice will be executed
- Introduction - Process of adding new methods or attributes
- Target object - Class with one or more aspects
- Weaving - Process of linking aspects with other application types or objects.
- Before: executes before a join point, but it does not have the ability to prevent execution flow from proceeding to the join point (unless it throws an exception).
- AfterReturning: executed after a join point completes normally i.e if a method returns without throwing an exception.
- AfterThrowing: executed if a method exits by throwing an exception.
- After: executed regardless of the means by which a join point exits (normal return or exception encounter).
- Around:surrounds a join point such as a method invocation.
- Stand-alone JARS
- Embedded web server (tomcat), which are replaceable.
- Starter POMs
- Spring actuators - management endpoints for going through the application internals.
- Logging and security
- Spring framework for web developement.
- Provides loose coupling between input logic (Model), business logic (Controller) and UI logic (View)
Dispatcher Servlet - Handles all Http Reqeusts and provides response
- View Resolver will identify the view that is needed to render (Support HTML, JSP, JSF, XSLT ..etc).
- Defautl view resolve is InternalResourceViewResolver.
- ContextLoaderListener loads and creates the ApplicationContext, so a developer need not write explicit code to do create it
- @RequestParam and @PathVariable