Tuesday 12 February 2019

What is Spring Boot and how it is related with Spring?

Spring provides loosely coupled IOC based approach, although spring saves a lot of object creation but it increases "configurations" and you have to create container object & specify where to look for an object, Apart from that you have to specify a lot of configurations for Database, Transactions, Security etc.

To solve these problems Spring Boot is developed.

Basically, Spring Boot is an independent project under the spring umbrella which automates the bootstrap (up & running) process of spring applications.



As Spring Boot is an opinionated framework  that means Spring Boot will put an opinion of configurations & jars and you can customized that as well.

If you just started learning Spring then you should start with Spring Boot because plain Spring whether it is core spring, web, data or security is old school stuff without boot. And in this blog "Spring Boot Series" will teach you all the concepts of Core Spring using boot and how it has reduced the efforts, and after that you can learn some other upcoming series like Spring MVC with Boot, Spring Data with Boot, Spring Security with Boot etc.

Advantages of Spring Boot over Spring:

1. Spring Boot provides intelligent defaults of jar files & configurations of different type of applications.

2. In plain Spring we have to create container by our self but with Spring Boot container will be already available for you.

3. There's no need to specify where to look for an object dependencies, Spring Boot will automatically do this for you.

4. Spring Boot provides a single way of executing all type of applications (whether it's a console application, web application etc.), all starts with a main() method like you used to do when you started learning JAVA.

5. Spring Boot provides embedded web-server for web application and rest services. So that they can be distributed as stand-alone application.

6. In the case of web application with Spring Boot you can have a war or even a executable stand-alone jar file that will include your code and web-server.

Saturday 2 February 2019

What is IOC and Dependency Injection? (Need of Spring with real life example)

The concept of IOC (Inversion of control) says just to use object and dependencies should be delegated (give responsibility) to a runtime environment that is IOC container in Spring.

IOC (Inversion of control) deals with 3 things:

        1. Object Creation,
        2. Dependency Satisfaction and
        3. Lifecyle Management.

For instance, Let an application wants to use an object A which needs another object B. So, the "Conventional Approach" is here's the diagram that shows an application wants to use A that is dependent on B.

In "Conventional Approach" there are 4 steps and all are from application side:

        1.0 - Application firstly creates A object,
        1.1 - Application creates B object as well,
        1.2 - Reference of B is given to A
        1.3 - A object is used by application (i.e. some method is invoked on it).

Now look at "IOC Based Approach", the scenario is same an application wants to use A that needs B.

In "IOC Based Approach" there are 6 steps but only 2 from application side that is requesting for an object and using it:

        1.0 - A object is requested by application,
        1.1 - A object is created by the container,
        1.2 - B object is created by the container to satisfy the dependency of A,
        1.3 - Reference of B object is given to A object,
        1.4 - Reference of A object is returned to the application,
        1.5 - A object is used by application (i.e. some method is invoked on it).


The IOC based approach is "Dependency Injection" that simply means IOC container is injecting/satisfying the dependencies and the main advantage of dependency injection is it solves maintenance problem.

And to clear your doubt, IOC is a concept and that follows this concept in Spring is IOC container. Name can be different in other languages like in angular we call it "Providers" but the concept is same.

In our real life IOC is everywhere, Let's take some real life examples. When you tell your mom that you're feeling hungry and you need food then your mom will put whatever available in the kitchen like rice,veggies etc. in a plate and serve to you that's what IOC does for you. You simply ask for an object, IOC container will create and satisfy all the dependencies and give that object to you.

Now let's take another example, to drive a bike you're not making roads. Roads are already made available to you, all you need is just drive your bike.

And this spring boot series will be focusing on all the concepts of spring in-depth using spring boot because plain spring is old school stuff.

Saturday 26 January 2019

What is Spring?

Spring is a general purpose framework which does not confine (limit or restrict) itself to any specific domain i.e. it can be used in a console application, web application, enterprise application or a web service.

It is basically based on 2 fundamental concepts:
        1. Inversion of control (IOC)
        2. Aspect-oriented programming (AOP)

IOC Deals with object creation, dependency satisfaction and lifecycle management. In simple terms the concept of IOC states that "application programmers should only be concerned with the use of objects". The creation and management should be "delegated (give responsibility) to a runtime environment" which is called IOC container.