Spring — Introduction | Code Factory

Spring Tutorial Index Page: Link

  • Spring Developed by Rod Jhonson.
  • Initial Name is Interface 21.
  • Spring came for alternative for EJBs (Enterprise Java Beans)
  • In case of EJB application became heavy weight and tightly coupled, Spring are light weight and loosly coupled.
  • For Banking application EJB is sutable but if it is a small scale E-Commerce application and budget is limited then EJB is not sutable. We need to have some free sources and that free sources are Spring.
  • Spring are light weight and AWT (Abstract Window Toolkit) are heavy weight.
  • While running AWT it will use OS libraries so it is heavy weight. But in case of Spring, Springs are not have any dependencies of OS, It will use JDK’s libraries. Spring are not having any dependencies of Application Server. You no need to have any Application Server. EJBs are having dependencies of Application Server so EJBs are heavy weight.
  • Loosly coupled example is like currently you use Airtel number after that you want to change sim provider then you port from Airtel to BSNL. Loosly coupled is possible because of Java Runtime Polymorphism (JRP).
/* Basic info of servlet */interface Servlet {
}
abstract class GenericServlet {
}
abstract class HttpServlet {
}
class HelloServlet implements Servlet {
}
  • * To get capabilities of Servlet we must have to implement Servlet inteface or extend servlet classes. But in case of Spring they are not force to implement any interface or any classes. If you require Spring feature, instead of implementing interfaces and extending classes you can take here class reference as a associated reference. By associate them we can get B and C class behaviour, Spring recommending us associate instead of inheritance, they are recommending has-a relationship. Then your class became light weight. Use associate model instead of using extending model your class will became light weight.
interface A {
// lets say this is Spring interface
}
class B {
// lets say this is Spring class
}
class C {
// lets say this is Spring class
}
class D {
// normal class
B b = new B();
C c = new C();
OR
B b;
C c;
}
  • In case of association your class not having tightly coupled with other classes. But in case of inheritance principle your class must have dependency of interfaces and classes.
  • So to make your application loosly coupled they are using here association rule. In case of associate any other class object here (in class D), then your class call it as POJO class because here we are not extending any other API, if it is a simple class w/o implementing any class then it is POJO classes.
  • By using Runtime Polymorphism and Association principles (Has-a relationship) Spring people implement Spring Framework.
  • In Inheritance principle we can create objects like A a = new B() because class B implement A or extend A.
  • But in Association principle to create A a = new B(), for that we can use reflaction API. In Spring we have container (IOC) support, we maintain XML document, by reading XML document pass argument to POJO classes.
  • * In IOC we have 3 containers. These 3 are interfaces.
    1. Core (BeanFactory (I) -> XmlBeanFactory ©)
    — BeanFactory b = new XmlBeanFactory();
    2. J2EE (ApplicationContext (I) -> ConfigurableApplicationContext (I) -> ClasspathXmlApplicationContext ©)
    — ApplicationContext a = new ClasspathXmlApplicationContext();
    — ConfigurableApplicationContext = new ClasspathXmlApplicationContext();
    3. Web (WebApplicationContext (I) -> WebApplicationContextUtil (Factory Class)) (It is in Spring MVC)
    — WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
  • * What is Container or What Container do?
    — Read xml file
    — Create instances of xml beans (classes)
    — After creating objects it will manage the lifecycle of bean classes
    — It will dynamic pass parameters from xml to bean classes
  • DI (Dependency Injection) is the main asset of IOC Containers.
  • To make a Spring application must we need to have a xml file and POJO classes. The main required components for spring application to start a container are below.
    — POJO class
    — xml file
    — Driver class
  • The main root tag for spring application file is <beans></beans>.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

March Release of Saleor: Dark Mode, Model Translations and… Saleor Cloud!

How to use the official Terraform Docker image

Storybook + Netlify CMS

Hola People 🎭

Adding Lambda functions to your Netlify hosted Gatsby site with Golang

Screen Scraping Becomes API Calling — Gathering OpenWorld 2017 Session Catalog with Node.js

Get around Slack message limits with this archive solution

UI Manager Setup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Java libraries (Java API)

IoC and DI in Spring

Naming Conventions in Java

Java Virtual Machine