Spring Containers: Beans are constructed even if you never try to get it by default.

This is a concept might be overlooked by the beginners in Spring framework. When a Bean configuration is loaded in a IoC container, all the beans are constructed by default if you don’t specifically mentioned lazy loading on a bean. So,

Read More »

Advertisements

Spring bean scopes

I just learned it!

code dweller

When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, To force Spring to produce a new bean instance each time one is needed, you should declare the bean’s scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean’s scope attribute to be singleton.

The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.

Scope Description
singleton This scopes the bean definition to a single instance per Spring IoC container (default).
prototype This scopes a single bean definition to have any number of object instances.
request This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
session This scopes a bean definition to an…

View original post 33 more words

Spring Collection Injection: How does it actually work

I am learning Java Spring Framework out of personal interest. I am trying to understand how it works. Today I was learning dependency injection in Spring. I started with injecting java collections through xml beans. As you already know, if you want to set a property of primitive type, you need to put exactly the same property name in bean xml definition. I started with that for injecting a List collection named addressList.

Read More »