Skip to main content


Showing posts from September, 2019

Spring Framework Tutorial

Spring framework is a lightweight application platform that provides infrastructure support for Java EE applications. Though its core concept of Dependency injection and AOP Spring handles the infrastructure so you can focus on your application. Spring is lightweight and enables you to build applications from "plain old Java objects" (POJOs) and enterprise services are injected non-invasively to POJOs. Spring Framework Modules Spring framework is modular in design and this layered architecture is one of its biggest design advantage. This modular design make Spring a logical choice in many scenarios, from embedded applications that run on resource-constrained devices to full-fledged enterprise applications that use Spring’s transaction management functionality and web framework integration. The Spring Framework consists of features organized into about 20 modules. These modules are grouped into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Progr

Java Finally Block - Exception Handling

When an exception is thrown in a code the normal execution flow of the method is disrupted and that may result in opened resources never getting closed. In such scenarios you do need a clean up mechanism that’s where finally block in Java helps. For Example, suppose in a method you open a file and start reading it using input stream. While reading the stream an exception is thrown and the code to close the stream is never executed. That means you have a stream that is still using resources because it was never closed. By using finally block and keeping the code to close the stream in that finally block you can ensure that the code to close the stream is always executed. Table of contents Finally block Finally block Java example What happens if the exception is thrown in the finally block Finally block with return When is Java finally block not executed Finally block Finally block in Java exception handling can immediately follow the try block making

Spring Bean Definition Inheritance

Just like the OOPS concept of inheritance is used in object oriented language where child class can inherit attributes and methods of a parent class same way in Spring framework child bean can inherit configuration data from a parent definition. In this post we’ll see how bean definition inheritance works in Spring. Table of contents Bean definition inheritance How does bean definition inheritance work Spring Bean definition inheritance Example Abstract attribute in Spring Bean definition inheritance Parent bean as Template in Spring bean inheritance Bean definition inheritance in Spring A bean definition can contain a lot of configuration information, including constructor arguments, property values, and container-specific information, such as the initialization method, a static factory method name, and so on. A child bean definition can inherit that configuration information from a parent bean rather than defining everything again. The child definiti

Spring Bean Scopes

Using a Spring bean definition, Spring container not only instantiates a bean and wire its dependencies it also provides the scope of the objects created from a particular bean definition. There is inbuilt support for six spring bean scopes in Spring Framework. Out of these six bean scopes four are available only if you use a web-aware ApplicationContext. You can also create a custom scope. Table of contents Supported Spring bean scopes Singleton scope Prototype scope Session scope Application scope WebSocket scope Supported Spring bean scopes Singleton scope - Single object instance corresponding to a bean definition is created for each Spring IoC container. Singleton scope is a default bean scope. Prototype scope - New object instance is created every time bean is requested from the Spring container. Request scope - For each HTTP request new bean instance is created. This Spring bean scope is valid only in the context of a web-aware Sprin