Java, Software Development, Spring

Spring Framework Minimum Dependency for IoC

Nowadays, most of us use Spring Boot, and we tend to skip the basics of the Spring Framework. Even those new to Spring would not think twice about turning to Spring Boot to develop new applications. Without Spring Boot, how can we have an application that uses the minimum Spring Framework dependency for IOC?

Spring Framework With Spring Boot

Without Spring Boot, we craft our pom.xml – not from scratch! Consider the following pom.xml file. We stripped it down from its Spring Boot version to the bare minimum. From hereon, we add the bare minimum dependency for an application that only uses the Spring Framework IoC.

The Only Spring Framework Dependency We Need: spring-context (IoC)

To have an application that has the essential dependency for us to try out the framework’s IoC feature, we only need the spring-context. For example, we can have the following lines in our pom.xml

Does it look too good to be true? It does. But the spring-context dependency has other dependencies. When we build our application, Maven uses that dependency information within spring-context to fetch the other dependencies.

Spring Minimum Dependency IoC

Therefore, the minimum number of dependencies we need for a Spring application that only uses IoC is 6. These are spring-aop, spring-beans, spring-context, spring-core, spring-expression, and spring-jcl.

Testing Our Spring Application for IoC

Now we can craft some codes and test our Spring application for IoC. To do that, we need some actual codes.

We have codes that represent a service and a DAO it uses.

Then, we have the configuration file that will instruct Spring on how to combine our beans. In this case, Spring will create instances of Dao and Service classes. Then, it will inject the Dao object into the Service object.

Lastly, we have the main Java class.

When we run the codes, we get the following output.

Spring Minimum Dependency IoC

Download the codes from this GitHub URL.

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like