From the course: Spring Framework in Depth
Introduction to Spring - Spring Framework Tutorial
From the course: Spring Framework in Depth
Introduction to Spring
- [Instructor] As we dig into the Spring Framework in depth, it is important to level set on exactly what Spring is and why it has become the most popular framework for the JDK. Spring is a framework that provides the plumbing for an application, so you as the developer can focus on business processes or user needs instead of the underlying needs of the application. Spring is an open-source project backed by Broadcom. The power of Spring really starts with this community. The core committers are all fantastic developers and the community only makes them better. They're all very active in answering questions responding to bugs and sharing their opinions on how to use Spring in the most effective manner. Spring was and still is to a large part, still focused on enterprise abstractions. It is really the bread and butter of its operational usage. However, Spring is fully capable of supporting internet-focused applications. With the advent of microservices architectures where Java is the language of choice, Spring really shines with Spring Boot and embedded application servers. Spring is really lightweight. I know many users of other frameworks will laugh at that comment, but if you look at the feature sets Spring provides and the way the projects are broken apart to optimize workflows, it really is a lightweight framework. Consider especially traditional Jakarta EE implementations, formerly Java Enterprise Edition, the Spring packaging and abstractions are much smaller. Spring is also very unobtrusive. If you build your applications using best practices and current recommended strategies, you can dramatically reduce your dependence on imports from the Spring catalog. Through the use of abstractions of facades, you can actually keep your business logic completely intact while not requiring any Spring imports in those class files. So let's spend a moment and talk about the most popular use cases for Spring, and that is starting with the enterprise itself. With Spring, especially Spring Boot, there is no need for heavy application servers. Even if you don't use Spring Boot, Tomcat is sufficient to run your packaged WAR file. However, most users today are building executable JARs with the app server embedded in it. Spring achieves much of this by abstracting from the heavy enterprise system APIs that come with Jakarta EE. That doesn't mean you don't still have access to technologies like JMS. You just abstract them away from the application server. By leveraging this in your ecosystem, your code is simpler, but so is your operational burden. By leveraging dedicated systems instead of large application server implementations, you make your code easier to distribute and scale as well. I have mentioned business logic a lot already and it is a key win for Spring. Think of how complex and repetitive it is to set up a JDBC connection, build a query, and execute it, and then read the results into an object all while shutting down the results set and the connection. Now repeat that for every database query in your application. Then expand that by every other common system that you use. This literature code with copy and paste that is error prone at best. With Spring, that all just goes away. The framework handles it for you, so your code is just the business logic. And ultimately that is really what you care about. Another big benefit of Spring is the dependency injection aspect of the framework. Spring manages all of your runtime dependencies by allowing the framework to maintain these objects, you don't have to deal with the creation and maintenance of these objects. This greatly decreases the complexity of your code, which of course improves your maintainability. It also helps you avoid some of the most common issues around memory management that can creep into Java-based applications even with its automatic garbage collection. With Spring, you create these objects once. This is done either through configuration of the application context or through formal object creation and configuration with JavaConfig. At the point the object is configured, it is maintained by the application context until the application closes. This is a technique that does take some getting used to as with any dependency injection-based framework. But we are going to spend some time talking about it in much detail later.