Posts

Showing posts from October, 2009

When to use value tag and value attribute?

A bean can be configured using either value attribute/tag, constructor injection. We should use value tag only when we need to configure a property instance variable in a class, else we should avoid it. Below is an example < bean id = "mappings" class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > < property name = "properties" > < value > jdbc .driver.className= com . mysql . jdbc .Driver jdbc . url =jdbc:mysql:// localhost :3306/ mydb value > property > bean >

Spring Basics

1) Loading properties from a properties file in spring application In Spring we have two ways of managing our application beans (a) BeanFactory and (b) ApplicationContext. BeanFactory provides basic functionality regarding bean management services whereas ApplicationContext provides more functionalities along with features provided by BeanFactory. To read a property from (.properties) file we should use ApplicationContext, we can not use BeanFactory because it does not have access to applcation resources. In this article we'll see how we can access properties from a property file: (a) spring configuration file - appliaction-context.xml xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:util = "http://www.springframework.org/schema/util" xmlns:tx = "http://www.springf