how to define the initial method ?

74 views
Skip to first unread message

wahaha

unread,
Jan 9, 2012, 10:01:13 PM1/9/12
to google-guice
<bean id="dd" class="aa.bb.C" init-method="start" destroy-
method="dstr">

in spring,we can define the initial method to run automatically after
the bean have been Instantiated.
how to do this in guice?
and i want guice to instantiate all beans that i defined in annotation
automatically,and then run the initial methon,not need me to use
Injector''s getInstance() method to get. how to do this?

Noctarius

unread,
Jan 10, 2012, 12:15:45 AM1/10/12
to google...@googlegroups.com

Hey,

you can use a Provider which instantiates your "bean" and call the
init method before returning the instance.

Noc

Thomas Broyer

unread,
Jan 10, 2012, 4:59:39 AM1/10/12
to google...@googlegroups.com
See http://code.google.com/p/google-guice/issues/detail?id=62

According to the javadoc, you should be able to do something similar (that wouldn't work in all cases, but IIUC would work for your init-method="" use case) with a TypeListener and InjectionListener.

There doesn't seem to be an equivalent for destroy-method="" though.

Dmitry Churbanov

unread,
Jan 10, 2012, 12:59:22 AM1/10/12
to google...@googlegroups.com
Another option is to call your initial method from constructor. If you don't have access to source code, then as Noctarius mentioned you can use provider.

-Dmitry


--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.


wahaha

unread,
Jan 10, 2012, 4:24:37 AM1/10/12
to google-guice
why my posts can not show in the list?

i have post several times,but only this post can been seem in this
list.

why the manager prohibit my posts?

Stuart McCulloch

unread,
Jan 10, 2012, 11:17:42 AM1/10/12
to google...@googlegroups.com

this list is moderated, so there can be a delay between posting and the post appearing in the list

Reply all
Reply to author
Forward
0 new messages