5

Is Spring Container is just like a jvm? or it is different? Why is Spring IOC mainly used? If it is for creating the objects without using new operator? what is wrong in using new operator?

If we are creating singleton objects and return the same object whenever application wants, we are loading all the objects on server start up? will that not make the application heavy?

If it is so, then why we need spring core? How is filter,bean post processor, aop is different? if aop is used for implementing cross cutting concern, why do we need beanProcessor interface?

user3035087
  • 81
  • 2
  • 11

1 Answers1

7

Is Spring Container is just like a jvm?

No, Spring is a Java framework. It provides classes you can use to run a Java application on a JVM.

Why is Spring IOC mainly used?

Learn what Inversion of Control is and you will understand why it is used so heavily.

If it is for creating the objects without using new operator? what is wrong in using new operator?

The new keyword forces compile time dependencies. Inversion of Control and Dependency Injection remove those dependencies, mostly through reflection.

If we are creating singleton objects and return the same object whenever application wants, we are loading all the objects on server start up? will that not make the application heavy?

You will usually want all those objects at startup so it's a non-issue. You can delay the initialization of those objects (beans) with lazy loading.

If it is so, then why we need spring core?

If what is so?

How is filter,bean post processor, aop is different?

The BeanFactory creates and initializes beans. A BeanPostProcessor is meant to wrap a bean in a proxy or modify that bean's properties. The javadoc has more details.

Aspect oriented programming is a style of programming. In order to implement it with plain old Java, you need to use JDK or CGLIB proxies. Those are applied using BeanPostProcessor instances by wrapping the processed bean. Calls going to the target bean will be intercepted by the proxy which will (possibly) perform logic before delegating to the target bean. Java's AOP capabilities are almost completely limited to method calls.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • `A BeanPostProcessor is meant to wrap a bean in a proxy` What is really mean by proxy in spring mvc? I have heard this word in spring scope discussions many times. – Govinda Sakhare Apr 24 '16 at 10:44
  • @piechuckerr Take a look at [`Proxy`](https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html). This is the basis of JDK proxies. CGLIB has its own class set for doing this. Proxies are just meant to intercept or wrap behavior before delegating to the actual object. – Sotirios Delimanolis Apr 27 '16 at 18:51