Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 94252 invoked from network); 13 Jul 2010 18:51:21 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Jul 2010 18:51:21 -0000 Received: (qmail 29354 invoked by uid 500); 13 Jul 2010 18:51:18 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 29316 invoked by uid 500); 13 Jul 2010 18:51:18 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 29308 invoked by uid 99); 13 Jul 2010 18:51:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 18:51:18 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of thechrispratt@gmail.com designates 209.85.216.176 as permitted sender) Received: from [209.85.216.176] (HELO mail-qy0-f176.google.com) (209.85.216.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jul 2010 18:51:11 +0000 Received: by qyk12 with SMTP id 12so6429286qyk.14 for ; Tue, 13 Jul 2010 11:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=iq6d/TLiAV69wNGOdyFmuMTVC+xp/KMpJRiXEECS1oc=; b=o+pd0rlTE7+PLlrqAZPt2FxJbLVBLRGyeV6PBOfaCXxnr4ThKf47FXMMtkmeMgnd1o YYjHHOy/bCi0NOHa0LfR2zYigwYGaezVdOyWHnPTpFCg1txwfMJpTuJ1Or9sOKTByBEG Ue9aoKfIQX32GLY/SlLgdLvgxHllNAIBP/DQQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=BvN9HIKv9jNa6nqCLXWjjrVn4MOze+iZSbufFeh6v8fJHfAgQYMgq6VuC63Ii6gWKN 5Y5iNwhJ7rddJ6xOrlALF43sYdLHhYmUTauMb8SqA3lW23lMsUZoUWOBdxP2Lw32JdIq toX7n7aaNxpd8v2oBqEcKMKeZlKdYTL6TwiUI= MIME-Version: 1.0 Received: by 10.224.107.138 with SMTP id b10mr9022350qap.244.1279046990297; Tue, 13 Jul 2010 11:49:50 -0700 (PDT) Received: by 10.224.19.196 with HTTP; Tue, 13 Jul 2010 11:49:50 -0700 (PDT) In-Reply-To: <29154226.post@talk.nabble.com> References: <28995322.post@talk.nabble.com> <45A4CFBF-37B1-4F4E-81C9-3882BB48D3D0@gmail.com> <29154226.post@talk.nabble.com> Date: Tue, 13 Jul 2010 11:49:50 -0700 Message-ID: Subject: Re: How to modify Struts2 start up process. From: Chris Pratt To: Struts Users Mailing List Content-Type: multipart/alternative; boundary=00c09f99e3d581fb3a048b49558b X-Virus-Checked: Checked by ClamAV on apache.org --00c09f99e3d581fb3a048b49558b Content-Type: text/plain; charset=ISO-8859-1 It's being called twice because, since you defined it as scope=singleton, Spring is creating a singleton instance for you automatically on start-up. Then your code is creating another instance in your getStartupService() method. You don't need to explicitly instantiate one, just let Spring inject it where you need it. (*Chris*) On Tue, Jul 13, 2010 at 11:42 AM, hisameer wrote: > > Thanks for the suggestion. I have implemented it, but the issue is that the > bean is called twice.I am using websphere server 6.1. Do you have any idea > why its happening? > > Here is the code in ApplicationContext.xml > > scope="singleton" init-method="init"> > > > > > > and StartUPService.java class looks like this: > public class StartUPService implements ApplicationContextAware { > > private static StartUPService ref; > > private ApplicationContext ctx; > > private static Logger logger = > Logger.getLogger(StartUPService.class); > > private boolean flag= true; > > private ServiceDAO dao; > > private int days= 15; > > private StartUPService() { > // no code req'd > } > > public static StartUPService getStartUPService() { > > if (ref == null) { > // it's ok, we can call this constructor > ref = new StartUPService(); > } > return ref; > } > > public void init() { > > if (ref == null) { > // it's ok, we can call this constructor > ref = new StartUPService(); > long startTime = System.currentTimeMillis(); > loadRequiredObject(); > long endTime = System.currentTimeMillis(); > logger.info("The Total time taken is: " + (endTime > - startTime) > + " ms"); > } > > } > > private void loadRequiredObject(){ > if (dao== null) { > dao= (ServiceDAO) ctx.getBean("daoBean"); > } > //here I will do some processing using the database access using dao > service layer > } > > > satyanarayana katta wrote: > > > > Using the application level spring container would be sufficient with > init > > method set. > > > > Sent from my iPhone > > > > On Jun 25, 2010, at 11:36 AM, hisameer > > wrote: > > > >> > >> Hi, > >> > >> I am using Struts2.1.6+Spring2.5.6+Hibernate+JPA in my web application. > >> The > >> application server is JBOSS5. I have to implement a logic so that when > >> the > >> server starts I can execute some database scripts using my DAO service > >> layer. And this class is responsible loading some required variables > from > >> the database. The class should execute only one on the start up. > >> > >> Please give me some suggestions how to do this. If possible write some > >> sample code. > >> > >> Thanks, > >> Sameer > >> -- > >> View this message in context: > >> > http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p28995322.html > >> Sent from the Struts - User mailing list archive at Nabble.com. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > >> For additional commands, e-mail: user-help@struts.apache.org > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > > For additional commands, e-mail: user-help@struts.apache.org > > > > > > > > -- > View this message in context: > http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29154226.html > Sent from the Struts - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > > --00c09f99e3d581fb3a048b49558b--