File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Bean initialise on start up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Bean initialise on start up" Watch "Bean initialise on start up" New topic

Bean initialise on start up

Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
Hi Guys,

Just a quick Spring Framework Bean question. I want to configure the application context to initialise a bean on start up.

Bean extends SimpleJdbcDaoSupport, it has a connect method defined which is called from the beans constructor.
The connect method basically does some sql querys, then perfroms some function based on results.

Scenario is:
Deploy the web app;
On start up application context see's the bean should be initialised,
Initialised the bean, which then perfroms the connect method.

This is my application context which points to the bean:

<bean id = "sessionManager" class = "com.example.beans.SessionManager">
<property name = "dataSource" ref = "dataSource"/>

I have tried addind auto-wireing tags and init-methods to make it work, but so far i have not successfully made the bean call the connect method on start up. The app will basically deploy and then that would be it.
Any help, im sure its prob something small and easy.

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Hello Mark,

I kept a SOP in nullary constructor in one of my beans. When I start the server, I see that SOP in console. So I would ask, does your constructor gets called? Do you see any error?
Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
Hi Vishal,

I found this online,

About half way down in section 3.4.1. Lifecycle interfaces, i found what i was after in the form of the init-method and implements InitializingBean. I got it working then. I also found a prob with my logging which was not working so that why i thought other areas were not working.

I agree. Here's the link:
subject: Bean initialise on start up
It's not a secret anymore!