Guice , afterPropertiesSet
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Someone knows some way that how can I achieve the same functionality in Guice as the ' afterPropertiesSet ' interface in spring ? ( its a post construction hook ) 回答1: By far the simplest solution, if you're using constructor injection and not doing anything too crazy, is to create a post-construction method and annotate it with @Inject : final class FooImpl implements Foo { private final Bar bar; @Inject FooImpl(Bar bar) { this.bar = bar; ... } @Inject void init() { // Post-construction code goes here! } } When Guice provides FooImpl, it'll