Image Image Image Image Image Image Image Image Image Image

Mudassir Shahzad | October 21, 2017

Scroll to top

Top

No Comments

Why Use Spring for Java Projects ?

Why Use Spring for Java Projects ?
Mudassir Shahzad

What is Spring ?
Spring is a framework that helps you to “wire” different components together. It is most useful in cases where you have a lot of components and you might decide to combine them in different ways, or wish to make it easy to swap out one component for another depending on different settings or environments.

Advantages

 

  • LightWeight

    Spring framework is very lightweight. Literally. The jar files of the core spring framework are very less in size.

 

  • Very Less Configuration Required

    To integration spring in your project, you need very less configuration.

    Spring can be used without XML (or very little)
    If you dive in with Spring 3.0.5.GA or higher then you can use the dependency injection support from JDK6+. This means that you can wire up dependencies using the @Component and @Resource annotations.

 

  • Dependency Injection

    Yes. Spring provides dependency injection. It may be like saying that a car is useful because it has tyres. BUT, hell, it’s true. Isn’t it ?

    What is Dependency injection ?
    Simple. You have a class, it has a private field (set to null) and you declare a public setter that provides the value for that field. In other words, the dependency of the class (the field) is being injected by an external class (via the setter). That’s it. Nothing magical.

 

  • AOP with Declarative Transaction Management

    AOP(Aspect Oriented Programming) is one of the main advantages of Spring framework. That is, if you require a common functionality in all or almost all of your classes, you can do it by using Spring AOP. Its achieved by providing an interceptor (a custom piece of code/ a method) before the method where you need that common functionality (cross-cuting concern). Or after the method. Or both.

 

  • Industry Support

    A lot of support is available online since Spring is a mature framework and there is a rare chance that you will face an error that nobody has faced before.

 

 

Spring mainly covers:

  1. Dependecy Injection
  2. AOP along with Declarative Transaction Management
  3. Spring MVC with Restful Webservices
  4. Foundational support for JDBC, JPA etc

Obviously, dependency injection promotes very easy unit testing since all your classes have setters for the important dependencies and these can be easily mocked using your favorite mocking framework to provide the required behavior.

That aside, Spring also provides a lot of templates which act as base classes to make using the JEE standard technologies a breeze to work with. For example, the JdbcTemplate works well with JDBC, the JpaTemplate does good things with JPA, JmsTemplate makes JMS pretty straightforward.

 

 

and you’re done. The parameters are injected and you just need to provide JAXB annotations for MyJaxbObject. That should take no time at all if you’ve auto-generated them from an XSD using the Maven JAXB plugin or Netbeans JAXB class generation funtionality. Note that there was no casting going on there, nor was there a need to declare a marshaller. It’s all done for you.

 

Other than that, a lot of spring modules projects are available as plug-n-play projects and can be utilized accordingly.

View here
http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/overview.html#overview-modules

 

 

Rererences

http://projects.spring.io/spring-framework/

Submit a Comment