This Spring article will help for the beginners and experienced. We will try to the best to share the knowledge in-depth concepts of Spring Framework with few examples and coding tips.
Spring is an application framework also known as Enterprise Application Development. It is an IOC (Inversion of Control) container for the Java. Spring helps to build Web and Standard-alone applications. Spring Applications are build using java language.
The latest version of Spring framework is 5. Spring framework is associate with different layers to make a perfect Web Application. Web development in different domains like Banking, ERP, e- Commerce, POS and beyond is remarkable.
Spring was developed by Rod Johnson in 2003. Spring framework makes the easy development of Java Enterprise Application Development.
Spring Framework supports to different frameworks like ORM Framework Hibernate, IBatis, Struts, JSF, EJB etc.
Spring AOP (Aspect Oriented Programming)
Spring Web MVC
We will be learning all these modules in detail with code tips, but before stating the modules let’s start learning about the IOC and Dependency Injection first.
IOC Container and Dependency Injection-
To start working with Spring we will need to know about container and Injections. IOC is the container which starts Spring Application.
Let’s divide this as 2types of container.
Bean Factory –
Bean Factory is an interface. Bean Factory Container is the simplest which provides basic support of DI. Spring Container is implemented through BeanFactory Component of the Framework. BeanFactory is implemented of Factory Design Pattern.
Package : org.springframework.beans.factory.BeanFactory
Resource resource = new ClassPathResource(“spring-appl.xml”);
BeanFactory factory = new XmlBeanFactory(resource);
TODO:check BeanFactory in notebook
Application Context –
Application Context is an extension of BeanFactory Component. Application Context will be have little more extra feathers than Bean Factory, which means more feature –rich version of Bean Factory.
Package : org.springframework.context.ApplicationContext
ApplicationContext ctx = new ClassPathXmlApplicationContext(“conf/appContext.xml”);
ApplicationContext ctx = new FileSystemXmlApplicationContext(“conf/appContext.xml”);
In high level, these are the few differences:
1) Bean instantiation/wiring
2) Annotation based DI is not supported
3) BeanFactory doesnot support internationalization (I18N).
1) Bean instantiation/wiring
2) Annotation based DI is supported
3) BeanPostProcessor registration
4) BeanFactoryPostProcessor registration
5) Applcation Context supports internationalization (I18N).
6) ApplicationEvent publication
TODO:check Aplciation Context in notebook
In general if we want to keep dependency classes in a class, we code in the below way which makes tightly coupled.
homeAddress = HomeAddress ();
Using Dependency Injection, we can write the above program in this way
this.homeAddress = homeAddress ();
The above DI code will make loose coupled, we don’t need to modify the code if logic is moved to new setup. In Spring framework, IOC container responsible is to inject the dependency. We will code IOC container details either by XML file or annotation based.
We will divide Injection in 2 ways.
We will learn DI along with different core concepts in Spring Core Module.
Spring Core-FrameWorks Next Page