01.Introduction to Spring

11 minutes
Share the link to this page
Copied
  Completed

Transcript

In this session, let us get an introduction to spring. Together with that, let us also have an overview of spring architecture. water spring, spring is an open source framework for developing enterprise applications in Java. Spring is lightweight, it uses for your base programming model to support developing loosely coupled applications. The core features of spring help in developing Java applications creating a Java application is very simple. We have done a number of times then why do we need spring because spring uses dependency injection What is the meaning of dependency injection and how are the supporting loosely coupled applications Let me explain now, say for example, you are having an user class, the user classes having few instances name, city and another class also an instance variable Address.

Now, when you want to create a user object and set these values what you will do, you are just going to write user use equal to new user u dot set name u dot set city and for address you need to create an address object address address is equal to new address then you would add that address this value array in this case, the user class and the address class are tightly coupled. The address class the user class depends on the address class, our user object depends on the address object, they are tightly coupled. This is a simple example. Let me go in for one other example. Then we are adding a layered architecture. Let me explain that we are having a service layer and a dmo layer from the service layer.

You're just going to make a call to the D layer. So what do you need? You need to have an instance of this DLL and the service layer. Say let me just have it as book The one book service. So inside book service, I'm just going to have it as book da vo, book service, the book da vo. So, if I want this to be second book service, I need to create an object of the walk and then set it to book service here they are tightly coupled as a developer, I am creating the object all by myself.

That is I need to say to the mot a quota newbie, why am pm and then I will be setting it to the book service. But with spring you don't have to do that whatever the dependencies of class is having it is identified by spring and it will be injected to this class. So because of this particular dependency injection concept, you can create loosely coupled applications. That is this book service is having an instance of ba ba has an interface it is having multiple implementation classes you are creating an object of that implementation class here, you are asking spring to inject that dependency into this boot service. What is the meaning of dependency injection whatever the currencies are there in a class will be created are injected to that particular class automatically. In this case, book service is a class book there was another interface with few more implementation classes.

The objects of boop da ba implementation will be created by spring and automatically injected to this book service class. This is the dependency injection there are different ways of achieving dependency injection we will be talking about that later. With spring you can develop loosely coupled application because of this concept of dependency injection And this is the Java application with spring You can also create enterprise application for this spring has got its own modules for supporting hibernate for supporting web applications. That is, we will be seeing all the modules like spring or spring servlets I sorry, spring web, then spring OIG some spring JDBC. You can plug them click whichever module you want core part. What about the enterprise application?

Spring has got modules, which makes enterprise application development very easier. The modules are like spring water and if you want to connect to hibernate, spring JDBC if you want to use database in the backend, and again, spring web if you want to create a web application. So there are many modules which are available in spring which helps to create this enterprise application. We will be seeing about this module we are discussing about this module. When we are learning the spring architecture, the advantages of spring spring helps to create enterprise applications using pojo plain old Java objects. With spring you can create loosely coupled applications.

This spring doesn't need any application server in case of enterprise application. You don't have to go in for WebSphere or Java, you can use a simple Tomcat for even an enterprise application. When you are developing an enterprise application with EJB enterprise Java B, you need an application server, but with spring you don't need that you need a simple Tomcat server. It is that lightweight IOC containers. inversion of control IOC means inversion of control this does the magic. This container is responsible for creating the objects and adding the dependencies to the appropriate classes.

So we will be learning about that just understand these IOC containers are lightweight. They are responsible for instantiating the spring beans spring is good for develop deploying applications on computers with limited memory and CPU resources because it is very lightweight. With spring you can create Kafka highly performing easily testable and reusable code because it is simple pojo it is reusable and it is also very easily testable access code use spring has got its own MVC framework with the help of which you can create web application. There are few other MVC frameworks like stretch, instead of using such you can go in for spring MVC framework. The reason is it is lightweight and it has got much more advantages compared to stress. The main thing is helps to create loosely coupled applications and the concept of dependency injection.

Spring also can integrate with other technologies like water famous it can integrate with hibernate logging frameworks like SL for the log back with j s. This class on JDK timers and other view technologies this spring helps to convert all the objects option into unchecked exceptions. What is the meaning of it if you are working with JDBC you would have seen check the exceptions like SQL exception class not found exception, it makes the developer mandatory to write the code within try and catch but with spring all these kind of database specific exceptions are converted into unchecked exceptions which may work very easy fighting is very simple. Then spring also attacks transaction management testing is easy in spring that also we have seen these are the advantages of spring framework. Do a recap of this advantages of spring spring support for Java bean style code based programming model.

With spring you can create loosely coupled enterprise application spring needs only Points Tomcat server it doesn't need any application server. Spring also supports integrating third party applica frameworks like warm framework logging framework view technologies and so on. It's spring which I mean the spring applications can be tested very easily because they are simple potatoes. So, these are the main and also spring has got IOC container which is very lightweight this IOC container is responsible for creating the spring objects and injecting the dependencies to the appropriate objects. So these are the advantages. While doing the application, you will still understand more about this IOC container and this dependency injection about spring architecture.

In the bottom part, you can see the score container. This is responsible responsible for creating Java applications using spring. It has not being poor context and expression language. Everything is going to be the module Corn beans modules, they take care of this IOC container context all this is also responsible for creating the instantiating the IOC container expression language just like how you got expression language in JSP. This expression language is used for setting and getting values with a cost in spring applications. Next data access integration.

If you want to connect to database from a spring application, you can use any of this module you can plug and play whichever module you want are a combination of in both JDBC to connect to a database you can use spring JDBC module spring or on this used to connect to a framework like hibernate, which is an ORM framework object relational mapping framework, why some object XML mapping, then JMS Java messaging services. So if you want to connect to any game or server, you can just use spring JMS modules and for taking care of the concepts Using transaction modules. Next let me come to the web part. If you want to create a web application using spring MVC, you can use web and servlets portlets for creating portlet based web application use portlet module. If you want to integrate spring and struts together you can go in for this such module such as also front controller, the dial profit, you can create web application up Aspect Oriented Programming aspects instrumentation, these are also few other modules which are available in spring AOP is responsible for cross cutting concerns.

That is in your Java application, you are supposed to take care of other services other than the business logic like logging security transactions. So instead of adding everything in the same part in the same course you can just separate it separation of concerns or cross cutting Concerns is called an AOP Aspect Oriented Programming. So I'm just giving an overview of water on some modules that are available in spring framework. What we are going to deal with this only this core core module that is core container core beans context expression language. I will also show you how to integrate spring with database using JDBC and using hibernate. So we will be using spring JDBC module spring water module which also includes transaction We will also learn how to work with how to create a web application using spring MVC module.

This is an introduction about spring. Going forward we will be learning more about dependency injection IOC container configuration metadata and so on. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.