Earlier we used to have EJBs for transactions, session management etc. Same thing can be achieved using Spring as well. So, I would like to understand how Spring became so popular and EJB is almost obsolete now a days. What is the gain we are getting following Spring framework?
Good question. I'll answer with my two cents. It's not that Ejbs aren't popular nowadays, it's the whole Java EE who is undergoing a deep crisis, at least in terms of general attraction.Java EE implementation s, i.e application servers, nowadays look like dinosaurs trapped in the tar. You need to be agile in adopting new Java language features, as well to use new libraries offering this or that feature previous versions didn't offer. Appservers need to be stable and somehow conservative.This means tahey can evolve only slowly.When I wanted to add websocket support to the appservers I am using in production well...simply, I couldn't.And modern IT world cannot withdraw this.
I don't know how this scenario will change with Jakarta EE. The need for fast paced updated appservers is a key goal for Jakarta EE project. Also, to be fair, I'd suggest you to have a look at microprofile initiative.More or less, micraoprofile aims to have a "spring like" approach within a Java EE context: you choose which piece of Java EE stack you want to use and, instead of deploying an application into an appserver, you will deal with a single fat jar with batteries included. Can't say how much popular is, though.