How to use PropertyPlaceholderConfigurer
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer is a bean factory post processor. This class can be used , when you want to provide some information to bean configuration file from external resource(property file).
For example most of the time we used to hardcode the database related information directly in the bean configuration file itself. Using PropertyPlaceholderConfigurer we can configure the connection information such a way that, we will give some place holder in the bean configuration file . Spring container pick up the value for that place holder from an external property file. This is the same concept we use in Ant.
Bean configuration
beanConfig.xml
<bean id="dataSource" destroy-method="close">
<property name="driverClassName"><value>${db.driverClassName}</value></property>
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${db.username}</value></property>
<property name="password"><value>${db.password}</value></property>
</bean>
Property file
Oracle.properties
db.driverClassName=oracle.jdbc.driver.OracleDriver db.url=jdbc:oracle:thin:@db-server:1521:db-schema db.username=username db.password=password
How to configure this property file into BeanConfig.xml
Simply configure PropertyPlaceholderConfigurer bean like other beans
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>Oracle.properties</value></property>
</bean>
<bean id="dataSource" destroy-method="close">
<property name="driverClassName"><value>${db.driverClassName}</value></property>
<property name="url"><value>${db.url}</value></property>
<property name="username"><value>${db.username}</value></property>
<property name="password"><value>${db.password}</value></property>
</bean>
Life@2010
This year lots of beautiful incidents happened in my personal and professional life. In Jan i have joined with Tata Consultancy Service. I got lots of new friends from my current employer Bhavik, Pradhamesh,Shanthanu.. But carrier wise nothing big is happened , still i got a position as module lead
. Didn’t get any challenging technical task this year. I believe that, my current employer has not utilized my innovative talent. But at the end of the appraisal they have given a good rating
. TCS has rated me Top 10 Developers in 2010. I doesn’t write more blogs this year. I will regularly update my blog this year. Personal point of view.. i am blessed to have a such a good wife.. she has supported me and stand with me some of the critical time of my life.. Rekha i love you..
I am wishing every one a happy new year
Started Tweeting
Started tweeting…. i created an account very before..
but now going to be active tweeter… Or forced to be tweet ..
he he..
find me here
One more Open source project
I am going to contribute for new open source project java-ws-discovery , this is a cross platform Java implementation of WS-Discovery specification. WS-Discovery is a Web Service discovery protocol that uses UDP multicast and SOAP/XML to discover new services. Current implementation is written by Magnus. I will be working with him for a new release based on the new specification.
Thank you Magnus Skjegstad , for making me as a part of this project.
my current reading
Why should you care what I read? . However, I know that some of you love to read.
what i want to say about this book is
“Prepare for an amazing journey where life gets better and better …
A special sunday in ashram..
Today Rekha and me went to Nerul Brahmagiri ashram for amma’s dharshan. Amma, One of the prominent spiritual leader in this century. She is one of the spiritual masters inspired me to search for the spiritual truth. And also met some of my old friends there. My wife and myself had a special dharsan today. I think this is a special day for my family. Tomorrow is holi so I am wishing you a colourful holi.
I changed my employer
I have changed my employer due to some professional issues with my previous employer. I have faced lots of issues there,But I don’t have anything bad to say about that company and the people who are working there. Because i learned a lot from that company. I hope my new employer is very good and they will give values to my talent and work. I wish all my old Colleagues, who were worked with me . And thanks a lot for the supports you are given me there in difficult situations.. especially to Dhanajay, Srini,..
StAX(Streaming API for XML) and Other parsers
To handle xml in java, there are mainly two API were used, DOM and SAX. But now StAX API is also part of java parsing API. Here I am writing some of the differences I found while learnig parsers for writing PojoXML open source project.
StAX
The main goal of StAX API(http://jcp.org/en/jsr/detail?id=173) is to give “parsing control to the programmer” by providing a simple iterator based API. This allows the programmer to ask for the next event (pull the event) ,because of this property StAX is called as pull parser .StAX was created to address limitations in the two most prevalent parsing APIs, SAX and DOM.
DOM vs SAX vs StAX
DOM creates a fully tree based structure of xml document in the memory and traverse randomly. DOM takes lots of memory. So its inefficient for processing large xml document.
But SAX parser is more efficient in terms of memory usage. SAX is a streaming API it parse sequentially when an xml Infoset found it fires events. SAX doesn’t provide random access to xml data. We don’t have control over the xml parsing. When an event(element or attribute or text or CDATA founds) occurs SAX parser send data to your program(Push Parsing).
In case of StAX (Pull Parsing) API we have to call parser API to get next element when we wanted. You can control the parsing from your code. Using Pull parser we can filter xml document, means we can ignore the unnecessary elements. Pull parsing library is smaller than push parser.
When there is memory limitation you should go for streaming API for example cell phone application.
Woodstox is a StAX implementation.
Which parser you are using? And How you handles xml parsing in your application
something about TDD
What is Test Driven Development?
This is question asked by one of my friend. Here i am writing my answer for that. Test Driven Development means writing Test Cases first and then developing code. This is best way to achieve a test suit. Its time consuming process, but in my open source project and my personal recomendation is to follow Test Driven Development. There are lots of reason i have found for that from the opensource project i have written and i am writing now.
i). Any time you can change the internal structure of the project without changing the functionality. Your test cases makes sure that your chages is right or wrong.
ii). Writing test cases will makes you to break down the code according to functionality. and ensures that that part is tested succesfully
iii). If a new person, who knows the project partially can add/change the code[no need to worry about wether its effect to other part of project]
iv). Doing TDD we can tell exact persentage of project status.
Some disadvantages are:
i). its boring task, not a creative work
ii) time consuming while following a faster schedule.
iii). Developer must have a good understanding on the automated testing API[JUnit or TestNG,..]
This all are my understandings that i got from books and my experiance.
please reply your comments on this
Life@2009
Another year saying by…
This year i made only few blog
Look on personal life,September we made a second honeymoon trip to Mahabaleshwar. Onam we celebrated in kerala. with our whole family. about 10 days we spend in kerala. we went to guruvayur temple and then to Veegaland also.
Look on professional view, had a absoutely eventful year. Moved to a different project within in the same company and it is very interesting to roll out the projects in a shorter time frames. Had oppertunity to work in
three different products. In between that lots of good friends left company. @ December i also resigned from the current employer. and new year is going to start with new company.
Me and my wife wishing you a happy and prosperous new year
