Archive | Spring

RSS feed for this section

Injecting Values using Spring Expression Lanugage

Spring Expression Language (SpEL) enables you to evaluate an expression dynamically and then use it in Spring’s ApplicationContext. For example, you could use SpEL to wire one bean into another bean’s property by using the bean ID as the SpEL expression: The same thing can be done without SpEL, then why it is needed? Let’s […]

Continue Reading ... Comments { 0 }

Spring Default Initialization and Destruction Callback

Spring provides a way to define default initialization and destruction for all beans defined in bean configuration file using default-init-method and default-destroy-method attributes on <bean> element. You don’t need to declare init-method and destroy-method on each individual bean. Following example demonstrates default initialization and destruction callback in Spring First create a new Java Project and […]

Continue Reading ... Comments { 0 }

Spring @PostConstruct And @PreDestroy

When creating an instance of a bean you might need to do some initialization to the bean. Similarly, when the bean is no longer needed and removed from the Spring container you might want to do some cleanup routine or destroy the bean. To do this initialization and destroy routine you can use @PostConstruct and […]

Continue Reading ... Comments { 0 }

Spring Init-Method And Destroy-Method

When creating an instance of a bean you might need to do some initialization to the bean. Similarly, when the bean is no longer needed and removed from the Spring container you might want to do some cleanup routine or destroy the bean. To do this initialization and destroy routine you can use the init-method […]

Continue Reading ... Comments { 0 }

Spring InitializingBean And DisposableBean

When creating an instance of a bean you might need to do some initialization to the bean. Similarly, when the bean is no longer needed and removed from the Spring container you might want to do some cleanup routine or destroy the bean. To do this initialization and destroy routine you need to implements the […]

Continue Reading ... Comments { 0 }

Spring Bean Life Cycle

The Spring Framework provides several callback interfaces to change the behavior of your bean in the container which includes InitializingBean and DisposableBean. The container calls afterPropertiesSet() and destroy() method to perform certain actions upon initialization and destruction. Initialization callbacks Implementing the org.springframework.beans.factory.InitializingBean interface allows a bean to perform initialization work after all necessary properties on […]

Continue Reading ... Comments { 0 }

Creating Custom @Required with Spring

To create a custom Required annotation, You will need to ensure that your custom annotation type is itself annotated with appropriate annotations for its target and runtime retention policy. First create a new Java Project and configure it as Maven Project. For Reference, Click Here Add the following dependencies in pom.xml 1. Creating Mandatory Interface […]

Continue Reading ... Comments { 0 }

Checking for dependencies

The Spring IoC container also has the ability to check for the existence of unresolved dependencies of a bean deployed into the container. This feature is sometimes useful when you want to ensure that all properties (or all properties of a certain type) are set on a bean. Table 1.1 Dependency checking modes Mode Explanation […]

Continue Reading ... Comments { 1 }

Spring PropertyPlaceholderConfigurer using Annotation

Spring 3.1 introduces the new PropertySourcesPlaceholderConfigurer that replaces the old XML <context:property-placeholder> This replacement class is created to be more flexible and to better interact with the newly introduced Environment and PropertySource mechanism. Following example demonstrates PropertyPlaceholderConfigurer using Annotation: First create a new Java Project and configure it as Maven Project. For Reference, Click Here […]

Continue Reading ... Comments { 0 }

Spring PropertyPlaceholderConfigurer

The PropertyPlaceholderConfigurer is used to externalize property values from a BeanFactory definition, into another separate file in the standard Java Properties format. This is useful to allow the person deploying an application to customize environment-specific properties (for example database URLs, usernames and passwords), without the complexity or risk of modifying the main XML definition file […]

Continue Reading ... Comments { 0 }