Guice call init method after instantinating an object

mgamer picture mgamer · Jan 19, 2010 · Viewed 30.3k times · Source

Is it possible to tell Guice to call some method (i.e. init()) after instantinating an object of given type?

I look for functionality similar to @PostConstruct annotation in EJB 3.

Answer

Simon Nickerson picture Simon Nickerson · May 20, 2011

You can just add the @Inject annotation to your init() method. It will get run automatically after the object is instantiated.