Home » spring beans » Page 2

Tag Archives: spring beans

Spring Bean Lifecycle Example

With this tutorial we shall show you how to use Spring’s initialization and destruction methods to control a Spring Bean’s lifecycle. Sometimes, specific actions need to be performed upon a bean creation or when a bean is destroyed. Spring provides simple ways to perform actions in a bean’s lifecycle start and end. The first way provided by Spring to perform ...

Read More »

Spring Dependency Checking Example

This is an example of how to check dependencies in a Spring Bean. A Spring Bean can have dependencies of any type, such as primitive types, Collections or even Objects that are references to other beans. Sometimes it is necessary that specific dependencies have to be set, so that a Spring Bean is instantiated correctly. Spring provides developers the ability ...

Read More »

Spring Bean Configuration Inheritance Example

This is a tutorial about the Configuration Inheritance between Spring Beans. In Spring, a bean definition can contain a lot of configuration information, including constructor arguments, property values, and container-specific information such as initialization method, static factory method name, and so on. A child bean definition is able to inherit configuration data from a parent definition. The child definition can ...

Read More »

Spring PropertyPlaceholderConfigurer Example

With this tutorial we are going to demonstrate how to use the PropertyPlaceholderConfigurer. The PropertyPlaceholderConfigurer is a property resource configurer that resolves placeholders in bean property values of context definitions. It pulls values from a properties file into bean definitions. We can use it to externalize property values from a bean definition in a separate file using the standard Java ...

Read More »

Spring Inject Date into Bean property with CustomDateEditor

In this example we shall show you how to inject a Date property in a Spring Bean, using the CustomDateEditor. The CustomDateEditor is a class provided by the Spring API and is used as a Property editor for java.util.Date, supporting a custom java.text.DateFormat. In order to use CustomDateEditor for date injection in a Spring Bean property, we first have to ...

Read More »

Spring Collections (List, Set, Map and Properties) Example

With this example we shall show you how to inject Collections in Spring Beans properties. The types of Collections that are supported by Spring are List, Set, Map and Properties. In order to show how the Collections can be injected in a Spring Bean we will create a simple Spring Bean with four properties, List, Set, Map and Properties. Our ...

Read More »

Spring Bean Scopes Example

In this example we are going to demonstrate the types of Bean scopes provided by Spring 3.2.3. In Spring a Bean definition is a recipe for creating actual instances of the class defined. The scope of the objects created by a bean definition can be chosen through configuration. The Spring Framework provides five scopes, that are described below: singleton : ...

Read More »

Spring Inner Bean Example

This is an example of how to use an inner Bean definition inside a Bean. In Spring 3.2.3, when a bean is only used as a property of another bean it can be declared as an inner bean. Spring’s XML-based configuration metadata provides the use of <bean/> element inside the <property/> or <constructor-arg/> elements of a bean definition, in order ...

Read More »

How to inject value into Bean properties in Spring

With this example we shall show you how to inject values to Spring Beans properties. Spring’s XML-based configuration metadata supports sub-element types within its <property/> elements for this purpose. Our preferred development environment is Eclipse. We are using Eclipse Juno (4.2) version, along with Maven Integration plugin version 3.1.0. You can download Eclipse from here and Maven Plugin for Eclipse ...

Read More »