Define the Spring Framework w/o using "IOC" or "Dependency Injection"

Posted by ryan
at 12:45 PM on Thursday, February 03, 2005

I am often asked (i.e. once every other year) by my coworkers, “What is Spring”? I usually launch into a long-winded diatribe of what it is followed by how it’s used and what it allows you to do. Most people get it, but I have decided it’s time to solidify that base definition of Spring so that it can be taken, alone, as a concise yet accurate definition of Spring. The people who ask me this are often bright Java guys, just unaware of the base concepts of Spring, IOC etc… so the definition can’t contain any of those buzzwords typically associated with Spring (kind of like explaining what “the” means without using the word “the”). My first attempt looked something like this:

Spring is a framework for transparently forming relationships between objects.

Ok, that statement is accurate but hardly embodies the full power of the framework. The word “transparent” is key and should be kept. We should also convey it’s lightweight nature and maybe the fact that it allows for the interception of it’s wired components using aspects? (but let’s not use the word “aspect”):

Spring is a lightweight framework that allows for the transparent management, wiring and interception of application components.

Ok, that’s a pretty tight definition of the base Spring functionality. Remember, I’m not trying to tell somebody everything Spring can do in one sentence, I’m just trying to convey the major functionality and potential of the framework. I’d like to add something in there about Spring’s ability to both replace or work with J2EE technology as Spring’s documentation goes to great length to stress both:

Spring is a lightweight framework, working in concert with or replacing J2EE, that allows for the transparent management, wiring and interception of application components.

But it also works in concert with many other standard Java frameworks and specs such as Hibernate, JDBC etc…, not just “J2EE”:

Spring is a lightweight framework that allows for the complete abstraction and encapsulation of implementation-specific technologies, like EJB, JDBC, Hibernate and others, by providing the ability to transparently manage, wire and intercept application components.

I feel like that’s a pretty good stab at it. My only fear is that I’m so engrossed in the making of the definition that it makes perfect sense to me while making absolutely no sense to any other reasonable person. That’s where you come in.. thoughts?

Comments

Leave a response

  1. Thomas RisbergMay 10, 2006 @ 08:22 PM
    Spring is the opposite of what you are used to. * If you spend a lot of time writing helper classes to configure your objects and look up resources, then Spring will take care of this for you and pre-populate your objects with references to what is needed. * If you have common code spread throughout your program to handle common things like transactions and security, then Spring will manage these aspects for you. * If you have a lot of code managing resources and accessing complex APIs with an endless chain of try-catch-blocks, then Spring will take care of this for you, leaving you with mostly pure business logic in your classes. The end result is that you end up with code that is more concise, consistently structured, based on interfaces and much easier to maintain.
  2. Keith DonaldMay 10, 2006 @ 08:22 PM
    Nice! Here's my shot: Spring is an application framework built on a lightweight container architecture that helps you structure, configure, and layer your application _consistently_. The capabilities of the core container, which is a sophisticated object factory, *eliminate* the ad-hoc glue code you typically find in any non-trivial application to instantiate and connect collaborating objects in a system (traditionally done via hard coded singleton lookups) and to source object configuration information (traditionally done in a ad-hoc fashion, from hard coded property file paths.) So in essence, the Spring container, which is fully usable in both J2SE and J2EE environments by the way, configures and connect the objects (or components, or services - pick your term there) that makeup the internals of your application in a loosely-coupled manner via well-defined interfaces. The container, acting as an "application assembler", selects your application objects implementations to instantiate, configure, and connect during application startup, and does all this external to the application objects themselves. It acts as a factory that conceals a single object's implementation, allowing dependent collaborators to be handed (aka injected) references to well-defined business interfaces that are focused on use for _their problem domain_ and not coupled with 'invasive' infrastructure code. The fact that it's the container's responsibility to instantiate and connect your application objects brings you power. That's exactly why Spring itself builds directly on its object factory (container) to offer runtime AOP capabilites to objects, for example, enaling dynamic decoration of application objects with cross-cutting behaivior configured in a declarative fashion. Leveraging techniques like JDK 1.3 dynamic proxies and cglib, Spring lets you transparently proxy your base application objects at creation time, and hand advised (proxied) objects to collaborators, without those collaborators ever knowing they're dealing with a decorated object implementation. In other words, the container allows you scale up object implementations (for example, as your application grows in complexity) in a controlled and often transparent manner, while keeping the external interfaces between objects simple, more constant, and manageable! To sum it up: *Spring enables a solid application architecture*. The frameowork's 'value-add services' , things like AOP, MVC, JDBC, EJB, Hibernate, Quartz, rich client, JMS/JMX integration , etc. are proof of the pudding: they all build on the base architecture and core "lightweight container" to bring these infrastructure services to you in "when you need them", easier to use, and best practice fashion. Hope this helps!
  3. Aaron GMay 10, 2006 @ 08:22 PM
    I like all of the these nuanced Spring definitions, but if you only have 5 seconds to convince a Spring-phobic developer that Spring is a Good Thing(tm), then my favorite tactic is to tell them Spring (and IoC in general) is "reverse garbage collection". (I forget where I first heard this description). In other words, Spring's core benefit is that it manages ALL of the object creation/init tasks, similar to how GC handles object cleanup. "Define it and forget it." The main advantage of using the term "GC" in the definition is that every OOP developer these days agrees that GC adds enormous value and frees us from writing tedious (and bug prone) cleanup code. So hopefully this definition breaks through the mental/emotional resistance in the old-school ad-hoc-favorin' developers and gets them to see IoC in the same positive light.
  4. Ballu CheguMarch 14, 2007 @ 04:07 PM

    Onething friends keep ask me “Why Spring is lightweight container vis a vis other containers say weblogic?” So, I would like to add to list of above definitions. Traditional J2EE containers must provide Servlet Container, EJB Container, JMS container, JTA, etc by spec to qualify JEE container. So when you run a traditional app server, its heavy weight with redundat containers running. Say if you just want a servlet container, appserver still load other containers. You may choose not to use them, but they still are loaded and thats why its called heavyweight container. On other hand, Spring just provides Templates or similiar wrapped objects for all these services and its up to you to choose which of these services you actually want. One more reason its called lieghtweight container is when you have to unit test your components, you dont need any real service provider. Say if u want to JMS part of your application architecure, you can use mock JMSTemplate objects (connection, queue, reader and writer) and test them in isolation, without a JMS provider. Where as if you are writing an application in any other container, you can’t unit test without the actual container running. So, even though your application needs all services(web, messaging, transactions, ..etc) in production environment, you dont need any of them to run your tests. I’m no Guru on Spring, you are free to correct me if my comments doesn’t make sense. Thanks