http://forum.springsource.org/showthread.php?t=55656
In case this blog content ever gets deleted here are the contents.
www.springsource.com
SpringSource basic
Community SpringSource Projects Downloads Documentation Forums Training Exchange Blogs
Go Back Spring Community Forums > Core Spring Projects > Web
Reload this Page load servlet on startup
User Name Remember Me?
Password
Register FAQ Calendar Today's Posts Search
Search Forums
Show Threads Show Posts
Tag Search
Advanced Search
Go to Page...
Reply
Thread Tools Display Modes
#1
Old Jun 9th, 2008, 06:19 PM
imbali imbali is offline
Junior Member
Join Date: Jun 2008
Posts: 1
Default load servlet on startup
Hi, I´m really new to the Spring Framework, so I might be making some very silly questions, but here goes:
Im working on an existing application that uses the Spring Framework. So here´s the thing, I would like to read some data from the db and perform some alterations to some of the data in it, but I wanted to do this when the web application was loaded.
I was thinking of creating a servlet that would deal with the alterations to the db and then in the web.xml define the "load-on-startup" and putting a smaller value than the value indicated to load the dispatcher servlet. So here´s my problem, I wont be able to access the db before the dispatcher servlet because then I wont be able to access the db, because all the hibernate configurations, datasource configuration are all done in the dispatcher serlvet.
Reply With Quote
imbali
View Public Profile
Send a private message to imbali
Find all posts by imbali
#2
Old Jul 8th, 2008, 07:15 PM
jfredrickson jfredrickson is offline
Junior Member
Join Date: Mar 2008
Posts: 10
Default
I know this reply is coming a month late, so I hope it's still of some use to you or anyone who comes along with the same question...
You could create a bean that handles your startup actions, then define that bean in your servlet config. Off the top of my head, it'd be something like:
Code:
Then perform your startup actions (DB updates, etc) in AppInit's startup method. As long as your servlet is configured to load on startup in web.xml, this should work.
Reply With Quote
jfredrickson
View Public Profile
Send a private message to jfredrickson
Find all posts by jfredrickson
#3
Old Jul 17th, 2008, 09:32 AM
brismith brismith is offline
Junior Member
Join Date: Mar 2008
Location: Taylors, SC USA
Posts: 8
Default
Great tip. Thanks.
Reply With Quote
brismith
View Public Profile
Send a private message to brismith
Find all posts by brismith
#4
Old Jul 17th, 2008, 10:21 AM
gregd gregd is offline
Member
Join Date: Nov 2005
Location: Athens, Greece
Posts: 76
Default
I think a BeanFactoryPostProcessor should be a better approach.
Otherwise you have to make sure your special bean (and consequently its init method) will be created after all your other beans to be able to use them.
Reply With Quote
gregd
View Public Profile
Send a private message to gregd
Find all posts by gregd
#5
Old Jul 17th, 2008, 11:40 AM
brismith brismith is offline
Junior Member
Join Date: Mar 2008
Location: Taylors, SC USA
Posts: 8
Default
I'll take a look at that too. I needed to do something almost identical to what imbali described, and jfredickson's suggestion worked for me. (I'm learning too.)
Reply With Quote
brismith
View Public Profile
Send a private message to brismith
Find all posts by brismith
#6
Old Jul 29th, 2009, 01:31 PM
moraesgp moraesgp is offline
Junior Member
Join Date: Jul 2009
Location: Brazil
Posts: 2
Post
I had the same problem. I need a class to load some properties from the databases as soon as Jetty started and put those properties in a servlet attribute to be used by all jsps during the life of the application.
I got it to work by making my class implement ServletContextAware and InitializingBean. And I made the injection of DAOs from the applicattionContext.xml.
The ServletContextAware makes sure I have access to the Servlet Context, so I can put the properties in a servlet attribute like context.setAttribute("staticUrl", properties.getStaticUrl());
The InitializingBean makes sure the method is only called after all the beans are injected in the class. Is pretty much the same as init-method="startup" mentioned by jfredrickson.
I´m only a year late but as long as Google is referencing the page, people will keep coming...
Reply With Quote
moraesgp
View Public Profile
Send a private message to moraesgp
Find all posts by moraesgp
Reply
Tags
load on startup
« Previous Thread | Next Thread »
Thread Tools
Show Printable Version Show Printable Version
Display Modes
Linear Mode Linear Mode
Hybrid Mode Switch to Hybrid Mode
Threaded Mode Switch to Threaded Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Rules
Forum Jump
User Control PanelPrivate MessagesSubscriptionsWho's OnlineSearch ForumsForums Home Core Spring Projects Announcements Core Container Data Access Web Spring Web Flow Spring Security Remoting and JMS AOP (Aspect Oriented Programming) Spring Development Tools Spring Application Performance Spring Management EJB Spring Web Services Spring-LDAP Spring Batch Spring Integration Spring Dynamic Modules Spring JavaConfig Spring BlazeDS Integration Spring Roo Meta Architecture Discussion SpringSource dm Server dm Server Announcements dm Server Installation and Configuration dm Server Application Development and Deployment dm Server Tooling dm Server General SpringSource tc Server tc Server Announcements tc Server General SpringSource Cloud Foundry Cloud Foundry Announcements Cloud Foundry General Spring Related Projects Spring Rich Client Project Spring-Modules Spring Extensions Spring Extensions Spring Python Spring db4o Spring sqlj Spring Workflow Spring Actionscript Spring se-jcr Spring Surf
All times are GMT -5. The time now is 07:25 AM.
Contact Us - Spring Framework - Archive - Top
Contegix provides first-class managed hosting and partial sponsorship of these forums.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
No comments:
Post a Comment