You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hisameer <co...@yahoo.com> on 2010/06/25 20:36:44 UTC

How to modify Struts2 start up process.

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


Re: How to modify Struts2 start up process.

Posted by Chris Pratt <th...@gmail.com>.
That should work great, another option is just to define a singleton bean in
your Spring configuration.  It will get loaded with the container and
initialized automatically.  Either method should do what you want.
  (*Chris*)

On Fri, Jun 25, 2010 at 12:24 PM, Dale Newfield <da...@newfield.org> wrote:

> Oh, and I forgot to mention, add a <listener/> segment to your web.xml so
> the application server knows to instantiate and call it.
>
> -Dale
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to modify Struts2 start up process.

Posted by Dale Newfield <da...@newfield.org>.
Oh, and I forgot to mention, add a <listener/> segment to your web.xml 
so the application server knows to instantiate and call it.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to modify Struts2 start up process.

Posted by satyanarayana katta <sa...@gmail.com>.
See if ur web.XML has the spring configuration configured twice.  We faced the same issue before

Sent from my iPhone

On Jul 13, 2010, at 11:42 AM, hisameer <co...@yahoo.com> wrote:

> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to modify Struts2 start up process.

Posted by Chris Pratt <th...@gmail.com>.
One thing I find odd is that you're creating a static reference to an
instance of your class, from an instance of your class, why?  Spring has
already created and is managing an instance for you, there's no reason to
instantiate a second singleton instance (kinda defeats the whole singleton
thing anyway).
  (*Chris*)

On Tue, Jul 13, 2010 at 2:25 PM, hisameer <co...@yahoo.com>wrote:

>
> Thanks for the input. The default scope is Singleton anyway. Also I am not
> calling getStartUPService() method in my application. I have deleted this
> method. But keeping the scope to singleton and init-method="init". The init
> method is called twice. Not able to figure that out.
>
> I know something is messed up. It should not be doing that. But I am not
> able to figure that out. I hope you understand my confusion.
>
> Sameer.
>
>
>
>
> Chris Pratt wrote:
> >
> > Umm, no I'm saying let Spring manage the singleton, you don't need to do
> > it
> > yourself.  Especially since the original question was how to have it
> > created
> > at initialization time.  If you remove scope=prototype, it won't be
> > auto-created for you, and you will have defeated the whole point.
> >   (*Chris*)
> >
> > On Tue, Jul 13, 2010 at 12:36 PM, hisameer
> > <co...@yahoo.com>wrote:
> >
> >>
> >> So basically you are saying is that remove scope="singleton"  right?
> >>
> >>
> >> Chris Pratt wrote:
> >> >
> >> > 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
> >> > <co...@yahoo.com>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
> >> >>
> >> >> <bean id="initBean"
> >> class="com.singleton.startup.service.StartUPService"
> >> >> scope="singleton" init-method="init">
> >> >>                <property name="flag" value="true" />
> >> >>                <property name="days" value="15" />
> >> >>        </bean>
> >> >>
> >> >>
> >> >> 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 <
> cool_sameer_for_u@yahoo.com>
> >> >> > 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
> >> >>
> >> >>
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29154837.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
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29155835.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
>
>

Re: How to modify Struts2 start up process.

Posted by hisameer <co...@yahoo.com>.
Thanks for the input. The default scope is Singleton anyway. Also I am not
calling getStartUPService() method in my application. I have deleted this
method. But keeping the scope to singleton and init-method="init". The init
method is called twice. Not able to figure that out. 

I know something is messed up. It should not be doing that. But I am not
able to figure that out. I hope you understand my confusion.

Sameer.


 

Chris Pratt wrote:
> 
> Umm, no I'm saying let Spring manage the singleton, you don't need to do
> it
> yourself.  Especially since the original question was how to have it
> created
> at initialization time.  If you remove scope=prototype, it won't be
> auto-created for you, and you will have defeated the whole point.
>   (*Chris*)
> 
> On Tue, Jul 13, 2010 at 12:36 PM, hisameer
> <co...@yahoo.com>wrote:
> 
>>
>> So basically you are saying is that remove scope="singleton"  right?
>>
>>
>> Chris Pratt wrote:
>> >
>> > 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
>> > <co...@yahoo.com>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
>> >>
>> >> <bean id="initBean"
>> class="com.singleton.startup.service.StartUPService"
>> >> scope="singleton" init-method="init">
>> >>                <property name="flag" value="true" />
>> >>                <property name="days" value="15" />
>> >>        </bean>
>> >>
>> >>
>> >> 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 <co...@yahoo.com>
>> >> > 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
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29154837.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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29155835.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


Re: How to modify Struts2 start up process.

Posted by Chris Pratt <th...@gmail.com>.
Umm, no I'm saying let Spring manage the singleton, you don't need to do it
yourself.  Especially since the original question was how to have it created
at initialization time.  If you remove scope=prototype, it won't be
auto-created for you, and you will have defeated the whole point.
  (*Chris*)

On Tue, Jul 13, 2010 at 12:36 PM, hisameer <co...@yahoo.com>wrote:

>
> So basically you are saying is that remove scope="singleton"  right?
>
>
> Chris Pratt wrote:
> >
> > 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
> > <co...@yahoo.com>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
> >>
> >> <bean id="initBean" class="com.singleton.startup.service.StartUPService"
> >> scope="singleton" init-method="init">
> >>                <property name="flag" value="true" />
> >>                <property name="days" value="15" />
> >>        </bean>
> >>
> >>
> >> 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 <co...@yahoo.com>
> >> > 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
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29154837.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
>
>

Re: How to modify Struts2 start up process.

Posted by hisameer <co...@yahoo.com>.
So basically you are saying is that remove scope="singleton"  right?


Chris Pratt wrote:
> 
> 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
> <co...@yahoo.com>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
>>
>> <bean id="initBean" class="com.singleton.startup.service.StartUPService"
>> scope="singleton" init-method="init">
>>                <property name="flag" value="true" />
>>                <property name="days" value="15" />
>>        </bean>
>>
>>
>> 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 <co...@yahoo.com>
>> > 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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-modify-Struts2-start-up-process.-tp28995322p29154837.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


Re: How to modify Struts2 start up process.

Posted by Chris Pratt <th...@gmail.com>.
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 <co...@yahoo.com>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
>
> <bean id="initBean" class="com.singleton.startup.service.StartUPService"
> scope="singleton" init-method="init">
>                <property name="flag" value="true" />
>                <property name="days" value="15" />
>        </bean>
>
>
> 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 <co...@yahoo.com>
> > 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
>
>

Re: How to modify Struts2 start up process.

Posted by hisameer <co...@yahoo.com>.
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

<bean id="initBean" class="com.singleton.startup.service.StartUPService"
scope="singleton" init-method="init">
		<property name="flag" value="true" />
		<property name="days" value="15" />
	</bean>


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 <co...@yahoo.com>
> 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


Re: How to modify Struts2 start up process.

Posted by satyanarayana katta <sa...@gmail.com>.
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 <co...@yahoo.com> 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


Re: How to modify Struts2 start up process.

Posted by Dale Newfield <da...@newfield.org>.
On 6/25/10 2:36 PM, hisameer wrote:
> I have to implement a logic so that when the server starts I can
> execute some database scripts using my DAO service layer.

implement a ServletContextListener that includes the method 
contextInitialized(ServletContextEvent event).

You should be able to get access to your business logic objects using 
getBean() method on the ApplicationContext.  Those business logic beans 
should have references to your DAO layer.  It's inadvisable for web 
layer code to directly access your DAOs.

ServletContext context = event.getServletContext();
ApplicationContext ctx = 
WebApplicationContextUtils.getRequiredWebApplicationContext(context);
bean = (BeanClass)ctx.getBean(beanName);

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org