使用Spring Configuration类,即不使用基于XML的配置。是否可以像Guice一样注入工厂方法?
如果我有像
这样的提供者方法,那就在Guice中 @Provides
public DatastoreService datastoreService(String url) { // Spring will inject this method parameter, if it is mapped of course.
return DatastoreServiceFactory(url);
}
春天有可能吗?
喜欢
@Bean
public Performer poeticDuke(Poem poem) {
return new PoeticJuggler(poem);
}
而不是:
@Bean
public Performer poeticDuke() {
return new PoeticJuggler(sonnet29());
}
这来自书籍Spring in Action 3