9
我有幾個服務實現一個通用接口,我希望能夠選擇其中的一個在我的應用程序啓動時注入其他服務。如何在Grails應用程序中選擇服務實現?
我試圖引用從resources.groovy服務實現,如下圖所示但隨後春天使所選服務的新實例,並且不自動裝配它的依賴。
我該如何獲得此解決方案?還是有另一種方式?
class MyService {
Repository repository
interface Repository {
void save(...)
}
}
class MySqlRepositoryService implements MyService.Repository { ... }
class FileRepositoryService implements MyService.Repository { ... }
resources.groovy:
beans = {
...
repository(FileRepositoryService) { }
}
所以基本上我的倉庫將是正常的Spring bean,而不是Grails服務。這將很好地工作。謝謝! –