“It is better to take many small steps in the right direction than to make a great leap forward only to stumble backward.”
- Louis Sachar through Julie911
Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Wednesday, November 30, 2011
Saturday, October 08, 2011
3 ways to initialize and destroy Spring beans
There are 3 ways to initialize (and destroy) spring beans
1. Using init-method and destroy-method attributes
2. Implementing InitializingBean and DisposableBean interfaces
3. Using @PostConstruct and @PreDestroy Annotations (available only in Spring >=2.5)
1. Using init-method and destroy-method attributes
Certain bean methods can designated as initializing and destroying methods using the init-method and destroy-method attributes. Like so:
<bean
id="studentService"
2. Implementing InitializingBean and DisposableBean interfaces
The bean can implement these methods InitializingBean.afterPropertiesSet() and DisposableBean.destroy(). Like so:
3. Using @PostConstruct and @PreDestroy Annotations
Note that both of these are JSR-250 annotations (here is a nice introduction to JSR-250 support introduced in spring 2.5).
@PostConstruct
public void subscribe()
{
// subscribe logic goes here
}
@PreDestroy
public void unsubscribe()
{
// unsubscribe logic goes here
}
1. Using init-method and destroy-method attributes
2. Implementing InitializingBean and DisposableBean interfaces
3. Using @PostConstruct and @PreDestroy Annotations (available only in Spring >=2.5)
1. Using init-method and destroy-method attributes
Certain bean methods can designated as initializing and destroying methods using the init-method and destroy-method attributes. Like so:
<bean
id="studentService"
class="initMethod.StudentServiceImpl"
init-method="subscribe"
destroy-method="unsubscribe"/>
2. Implementing InitializingBean and DisposableBean interfaces
The bean can implement these methods InitializingBean.afterPropertiesSet() and DisposableBean.destroy(). Like so:
public class StudentServiceImpl implements StudentService, InitializingBean, DisposableBean {
@Override
public boolean isExists(long studentId) {
// A fake implementation
if ( studentId % 2 == 0 )
{
return true;
}
else
{
return false;
}
}
@Override
public void afterPropertiesSet() throws Exception
{
// subscribe logic goes here
}
@Override
public void destroy() throws Exception
{
// unsubscribe logic goes here
}
}
3. Using @PostConstruct and @PreDestroy Annotations
Note that both of these are JSR-250 annotations (here is a nice introduction to JSR-250 support introduced in spring 2.5).
@PostConstruct
public void subscribe()
{
// subscribe logic goes here
}
@PreDestroy
public void unsubscribe()
{
// unsubscribe logic goes here
}
Wednesday, September 28, 2011
If the work is worthwhile, then whether we can complete it or not, it's worth making the attempt
If the work is worthwhile, then whether we can complete it or not, it's worth making the attempt. That's why courage is important.
- Dalai Lama
- Dalai Lama
Labels:
Attitude
Actions driven solely by anger are of no use at all
Actions driven solely by anger are of no use at all; realizing this can help strengthen your determination to resist it.
- DalaiLama
Labels:
Attitude
Wednesday, September 21, 2011
Every blessing ignored becomes a curse.
Every blessing ignored becomes a curse.
- Paulo Coelho in The Alchemist
Labels:
Attitude
Monday, September 19, 2011
One hand
"We are afraid of losing what we have, whether it's our life or our possessions and property. But this fear evaporates when we understand that our life stories and the history of the world were written by the same hand."
Sometimes, the caravan (in the middle of a desert) met with another. One always had something that the other needed - as if everything were indeed written by one hand.
- The Alchemist by Paulo Coelho
Labels:
Attitude
No matter how many detours and adjustments it made, the caravan moved towards the oasis.
"The desert was all sand in some stretches, and rocky in others. When the caravan was blocked by a boulder, it had to go around it; if there was a large rocky area, they had to make a major detour. If the sand was too fine for the animal's hooves, they sought a way where the sand was more substantial... If a guide were to fall ill or die, the camel driver would draw lots and appoint a new one.
But all this happened for one basic reason: no matter how many detours and adjustments it made, the caravan moved towards the same compass point. Once obstacles were overcome, it returned to its course, sighting on a star that indicated the location of the oasis."
- The Alchemist by Paulo Coelho
Labels:
Attitude
Tuesday, September 13, 2011
Don’t ask yourself what the world needs, ask yourself what makes you come alive
“Don’t ask yourself what the world needs, ask yourself what makes you come alive. And then go and do that. Because what the world needs is people who are alive.”
- Howard Thurman through Think Simple Now
Labels:
Attitude
Friday, September 02, 2011
Nice article on Spring 2.5 features
Here is a nice article on Spring 2.5 features.
Saturday, August 20, 2011
I am a parent and do not have the luxury of principles.
Father (who doesn't like his state going to war): I am a parent and do not have the luxury of principles.
...
Son (who is enlisting in the army): Father, I thought you were a man of principles.
Father: When you have a family of your own perhaps you will understand.
Son: When I have a family of my own I won't hide behind them.
- "The Patriot"
...
Son (who is enlisting in the army): Father, I thought you were a man of principles.
Father: When you have a family of your own perhaps you will understand.
Son: When I have a family of my own I won't hide behind them.
- "The Patriot"
Labels:
Attitude
Wednesday, August 10, 2011
when each day is the same as the next
"...when each day is the same as the next, it's because people fail to
recognize the good things that happen in their lives every day that the
sun rises."
recognize the good things that happen in their lives every day that the
sun rises."
"The Alchemist" by Paulo Coelho
Labels:
Attitude
Thursday, August 04, 2011
Money for good books
"No matter how tight our budget was over the years, we always made money available for good books." - Tim seldin in "How to raise an amazing child The montessori way"
Published with Blogger-droid v1.6.8
Labels:
Attitude
Monday, July 18, 2011
There isn’t a way things should be. There’s just what happens, and what we do.
“There isn’t a way things should be. There’s just what happens, and what we do.”
- “A Hat Full of Sky ” by Terry Pratchett through Julie911
- “A Hat Full of Sky ” by Terry Pratchett through Julie911
Labels:
Attitude
I don’t know the key to success, but the key to failure is trying to please everyone.
“I don’t know the key to success, but the key to failure is trying to please everyone.”
- Bill Cosby through Julie911
- Bill Cosby through Julie911
Labels:
Attitude
Friday, July 08, 2011
This is your life. Learn to enjoy what you’ve got.
“This is your life. Learn to enjoy what you’ve got.”
- Mr. Destiny through Julie911
- Mr. Destiny through Julie911
Labels:
Attitude
If we cannot love ourselves, we cannot fully open to our ability to love others or our potential to create.
“There are two basic motivating forces: fear and love. When we are afraid, we pull back from life. When we are in love, we open to all that life has to offer with passion, excitement, and acceptance. We need to learn to love ourselves first, in all our glory and our imperfections. If we cannot love ourselves, we cannot fully open to our ability to love others or our potential to create. Evolution and all hopes for a better world rest in the fearlessness and open-hearted vision of people who embrace life.”
- John Lennon through Juliee911
- John Lennon through Juliee911
Labels:
Attitude
Friday, June 24, 2011
Everybody is a genius
“Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.”
- Albert Einstein through Julie911
- Albert Einstein through Julie911
Labels:
Attitude
Wednesday, June 08, 2011
When there is no enemy within, the enemies outside cannot hurt you.
When there is no enemy within, the enemies outside cannot hurt you.
- African Proverb through a flourishing life
- African Proverb through a flourishing life
Labels:
Attitude
Monday, May 23, 2011
Reliable and genuine discipline
Reliable and genuine discipline comes not from repression, but from an
understanding of all the whys and wherefores of our actions.
understanding of all the whys and wherefores of our actions.
- Dalai Lama
Labels:
Attitude
The day we fret about the future is the day we leave our childhood behind.
“When we are children we seldom think of the future. This innocence leaves us free to enjoy ourselves as few adults can. The day we fret about the future is the day we leave our childhood behind.”
- “The Name of the Wind” by Patrick Rothfuss through Julie911
- “The Name of the Wind” by Patrick Rothfuss through Julie911
Subscribe to:
Posts (Atom)