Spring Expression Language – Referencing Static Methods and Members

Concept Overview In general, most of the beans declared for dependency injection using Spring are static and statically defined i.e. It is known a-priori what the dependencies are going to be. However, in certain advanced situations, there may be a requirement to perform dependency injection dynamically at runtime. Such dynamic dependency injection is possible in … Read more

Spring Expression Language – Referencing Beans

Concept Overview In general, most of the beans declared for dependency injection using Spring are static and statically defined i.e. It is known a-priori what the dependencies are going to be. However, in certain advanced situations, there may be a requirement to perform dependency injection dynamically at runtime. Such dynamic dependency injection is possible in … Read more

Spring p Namespaces

Concept Overview Spring’s P namespace is an alternative to using the property tag. By using p namespace, we can perform dependency injection by directly using the attribute of bean tag instead of using the property tag. The benefits of using p namespace are: p namespace is more compact than property tag Using p namespace reduces … Read more

Spring Injection – Properties

Concept Overview Sometimes, it is necessary to inject a Collection of type java.util.Properties into a bean using Spring injection. e.g. A Car has many technical specifications associated with in the form of name-value pairs (e.g. Weight, Maximum Torque, No. of cylinders, etc). This is achieved by using the props tag within the property tag in … Read more

Spring Injection – Map

Concept Overview Sometimes, it is necessary to inject a Collection of type java.util.Map into a bean using Spring injection. e.g. A TelephoneDirectory maps the name of a person with his telephone number. This is achieved by using the map tag within the property tag in Spring configuration. The following sample program provides an overview of … Read more

Spring Injection – Set

Concept Overview Sometimes, it is necessary to inject a Collection of type java.util.Set into a bean using Spring injection. e.g. A Team may contains a Set of Players. This is achieved by using the set tag within the property tag in Spring configuration. The following sample program provides an overview of injecting a Set of … Read more

Spring Injection – List

Concept Overview Sometimes, it is necessary to inject a Collection of type java.util.List into a bean using Spring injection. e.g. A ToDoList may contains a list of tasks. This is achieved by using the list tag within the property tag in Spring configuration. The following sample program provides an overview of injecting a List of … Read more

Spring Simple Value Injection

Concept Overview It is possible to inject simple values like String, Integer, etc. into a bean. This is done using the value attribute of property tag in Spring configuration xml. The following sample program provides an overview of injecting simple values into a bean. Sample Program Overview In the sample program, we will create a … Read more

Spring Factory Method

Concept Overview Normally, Spring instantiates a class and performs dependency injection. However, sometimes it may be necessary to instantiate a class via another class (usually called a Factory class). In such a scenario, Spring should not create the class on its own but simply delegate the instantiation to the Factory class. Spring provides a way … Read more

Spring InitializingBean and DisposableBean

Concept Overview Sometimes, after Spring beans are created, they need to perform some additional initialization operations so that they can carry out their responsibilities. e.g. When an ATM (Automated Teller Machine) system is started, it needs to connect to its bank’s network. Similary, sometimes Spring beans need to peform some cleanup operations before it gets … Read more