Most important things you should know about spring framework

Abdur Razzak
6 min readOct 24, 2019

--

Spring framework logo

Spring the popular framework name in the Java developer community most of the Java developers start learning java web development through spring framework. Before start learning spring you need to know some important points about spring so that you have been easily summarised your learning path of spring framework.

1. What is the spring framework?

Benefits of Spring Framework by JanBask Training
  • It is an application development framework for enterprise Java(J2EE).
  • There is an extension for building web applications on top of the Java EE platform.
  • Spring is a framework for dependency injection which is the pattern that allowed to build a very decoupled system.
  • The goal of spring is to make J2EE development easier to use and promote good programming practice.

2. What are the advantages of the spring framework?

Advantage chart of Spring Framework by Data Flair

Lightweight

  • The framework doesn't need to be completely loaded to be useful.
  • Use one framework without using another one.
  • It doesn't force the programmer to inherit any class or implement any interface and for that reason, it is said non-invasive, Enable you to write powerful, scalable applications using POJOs.

Flexible

Loosely Coupled

AOP Support

  • AOP stands for Aspect-Oriented Programming it is one of the key components of the spring framework.
  • It provides interceptors to intercept an application. Suppose, when a method is executed, you can add extra functionality before or after the method execution.

Easy to test

  • It provides robust testing modules that make application testing easier.
  • Again dependency injection makes it easier or gearing up the application testability.

3. Difference between Spring and Spring boot framework?

Spring vs Spring boot by stechies

Spring

  • XML based configuration.
  • Application creation or execution takes more time.
  • So many boilerplate codes you need to write.
  • Specify each and every dependency separately.

Spring boot

  • Annotation-based configuration.
  • Application creation or execution is much quicker.
  • Reduce the amount of boilerplate code.
  • Wraps dependencies together in a single unit in spring-boot-starter-web meven dependency.

4. What is autowiring in spring?

Spring Autowiring by huongdan
  • The process of injecting object dependencies.
  • Objects can be injected in the setter or constructor of a class.

5. What are the types of autowiring model?

  • No: No autowiring at all. Bean references must be defined via a ref element.
  • ByName: Autowiring objects by property name which is actually looking for the same bean name which needs to be autowired.
  • ByType: Autowiring by data type. If there is exactly one bean property type of the container. If there is more then one a fatal exception thrown.
  • Constructor: Autowiring by the constructor.

6. What is the IOC container?

Spring IOC container
  • A framework used to create and inject dependencies automatically.
  • There are two types of IOC container BeanFactory and ApplicationContext.
  • BeanFactory is a simple container used for dependency injection.
  • ApplicationContext is an advanced container used for dependency injection.

7. What are the bean scopes?

Bean Scopes in Spring

Determine the types of bean instances that should be returned. Here is the list of some important bean scopes in spring. framework.

  • Singleton: Return a single bean instance per Spring IOC container.
  • Prototype: Return a new bean instance each time when it requested.
  • Request: Return a single bean instance per HTTP requests.
  • Session: Return a single bean instance per HTTP session.
  • Global Session: Return a single bean instance per global HTTP session.

8. Difference between singleton and prototype scopes?

Singleton

  • Return a single bean instance per Spring IOC container.
  • The default scope is always singleton. However, when you need one and only one instance of a bean, you can set the scope property to singleton in the bean configuration file, as shown in the following code snippet −
<!-- A bean definition with singleton scope -->
<bean id = "..." class = "..." scope = "singleton">
<!-- collaborators and configuration for this bean go here -->
</bean>

Prototype

  • Return a new bean instance each time when it requested.
  • To define a prototype scope, you can set the scope property to prototype in the bean configuration file, as shown in the following code snippet −
<!-- A bean definition with prototype scope -->
<bean id = "..." class = "..." scope = "prototype">
<!-- collaborators and configuration for this bean go here -->
</bean>

9. What is the spring bean?

Spring bean
  • In a short, it's an Object managed by spring IOC container.
  • A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

10. What is Spring MVC?

Spring MVC by tutorialspoint
  • A Spring MVC is a Java framework that is used to build web applications. It follows the Model-View-Controller design pattern. It implements all the basic features of a core spring framework like Inversion of Control, Dependency Injection.
  • A Spring MVC provides an elegant solution to use MVC in the spring framework with the help of DispatcherServlet. Here, DispatcherServlet is a class that receives the incoming request and maps it to the right resource such as controllers, models, and views.

11. Some important annotations use in spring?

Spring annotations by DZone

@Component

  • Marks a class that will be registered in context as a bean.
  • Spring will autodetect these classes for Dependency Injection when an annotation-based configuration and classpath scanning can be used.

@Autowired

  • Spring autowired other beans in your class.
  • Spring Dependency Injection wires an appropriate bean into the marked class member.

@Controller

  • Mark a class as a controller in Spring MVC.

@RestController

  • Mark a class as a controller when developing Restful web service.

@RequestMapping

  • Map Url's to a class on a Handler's method when developing Rest web service application.

12. What are the different modules of Spring?

Spring framework modules

Spring Core

Data Access

  • The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules.

Web

  • The Web layer is related to web application development and it's consists of the Web, Web-Servlet and Web-Portlet modules.
  • Spring’s Web module provides basic web-oriented integration features, such as multipart file-upload functionality, the initialization of the IoC container using servlet listeners and a web-oriented application context. It also contains the web-related parts of Spring’s remoting support.

AOP, Aspects, and Instrumentations

  • Module dedicated to Aspect-oriented programming.
  • There is also a separate Aspects module that provides integration with AspectJ.
  • The Instrumentation module provides class instrumentation support and classloader implementations to be used in certain application servers.

Test

  • Support unit/integration testing using Junit and TestNG.

Conclusion

That's all for today, this is my first story writing inspired from when I'm start learning about spring basics for my interview preparation. I think every beginner spring developer should know these points so that the developer can easily relate other parts easily within a very short time. If you like my writings please don't forget to hit the clap button.

Thank you and Happy Coding!

--

--