- Spring empowers POJO based programming.
- It offers support for MVC out of the box
- wires up code in less time.
- How does it support layered architecture?
- provides an abstraction layer to simplify development process(why is this a benefit and how does spring handle this?) How does spring do that? I read a lot of articles talking about the advantages of spring. But none of them explain in theory i.e. in words not code, how spring does that? for example, one of the advantages says it empowers POJO programming? we can do that with plain java too, why is that a benefit or what's the opposite of POJO? Kindly request everyone to address those 3 questions. THanks
Asked
Active
Viewed 92 times
-1

Srs
- 59
- 8
-
This is way beyond the scope of a StackOverflow question. Start with the reference docs: https://docs.spring.io/spring-framework/docs/current/reference/html/index.html – Sean Patrick Floyd Jun 10 '21 at 21:59
-
can you answer any of them at high level or in a generic way? – Srs Jun 10 '21 at 22:09
1 Answers
0
in short:
- spring was created a long time ago. it was probably compared to ejb2 that needed more setup code. POJO vs EJB vs EJB 3 Also spring does support pojos for example as return value in MVC-controllers. pojos dont have external dependencies so your application stays portable (non-functional requirement of an application).
- yes you can easily (my opinion) create web applications.
- at its core spring provides a container in which bean definitions are stored. when a service is requested that needs a dependecy, spring can look up whether it has a bean definition for that dependency, construct an instance of that bean and inject it in that service. That way you dont need to manually instantiate your service.
- for example in web applications spring has abstractions for controllers, services and repositories. typically an application provides controllers so that caller can use your api. controllers should call services that handle your business logic. and services can call repositories that persist your data. that way you have a layered flow: controllers --> services --> repository this has the advantage that when you change e.g. your repository you dont have to make changes to your controllers.
- spring provides many abstractions for common problems out-of-the-box (e.g. spring security) and empowers convention-over-configuration. That way you can reduce boilerplate code. less code -> less probability for a developer to make a mistake. e.g. spring-security-oauth2: you can just set some properties in a .properties file and spring autoconfigures beans that solve the validation of an oauth-token when a user requests one of your controllers.

benebo22
- 241
- 2
- 5
-
Thanks for your answer. I have follow up questions about: 2. '_How_' does spring support MVC pattern? 4. The layered design you explained can be done in plain java as well. What is the role of spring and how does it support/help the same? 5. How does it provide abstraction for these layers? – Srs Jun 11 '21 at 01:08
-
2) spring supports the MVC pattern by givíng you the tools to easily establish the pattern in your application. 4) yes, the same can be done in plain java. but e.g. by using spring annotations like @Repository you are forced to declare a new class for database retrieval operations. in contrast you could also create a class that extends HttpServlet and open a database connection in that class. 5) e.g. controlles: you can directly work with java objects as arguments instead of parsing a http request body and map it to a pojo. so in that way spring abstracts the http body for you. – benebo22 Jun 11 '21 at 08:43