What is the Spring Framework in Software Engineering and how does it work?

317 views

If someone can preferably use an analogy to explain the Spring framework I’d really appreciate it.

It doesn’t have to be advanced, I just want a general understanding of how things used to be, and a layman’s explanation of how Spring makes the way things used to be a lot easier now.

In: Technology

Software frameworks in general, not specific to Spring, basically do the boring housekeeping things for you. Pretty much every application has a bunch of basic things to do (get input, perhaps refer to data, make decisions, send output); so rather than code that by hand in every application, you use a framework so you don’t have to worry about the “guts”. The framework also “forces” you to use a specific coding style, so that everything is consistent across different developers and different parts of the application. If you used a hypothetical perfect framework, all that would be left to be done is just coding the actual business logic (in reality it’s not *quite* that simple).

Spring in particular is designed to simplify developing enterprise-level Java applications.

Normal declarative programming requires you to tell a computer exactly what to do step by step and is very tedious like this sentence. It is inflexible; you compile and commit to a set program.

However, we want to save time and not repeat the same code over and over. You might want to tell the computer what program you want and have it write most of it for you, and adapt it to changing conditions without rewriting it. This is what Spring does.

For example, you might want to do something like just add a web server to your program. This way, all you have to do is write the custom parts you need for writing the server.

This is a task for a “high level programming language”. Java afaik is the most pervasive programming language. Java is not a high level programming language.

Spring works by writing code to inject the code you want in a smart way. In other words, it gives you the ability to do this high level programming task to just “drop in” a complicated component.

So, for example, you would say, “I need a web server for connecting REST API.” So you define a REST API component, set like 10 variables to customize it, and then the only remaining work is to define your specific REST URI. And here is the big benefit of Spring — you can change those ten variables at run time and still adapt to a changing situation.

Spring does this code injection when the programming is running. So unlike a typical Java program, where all the classes are defined ahead of time, Spring loads or injects the components you need dynamically.