我建立使用Grails 3.3.0和彈簧引導+ Grails應用程序春天啓動1.5.6.RELEASE構建上下文(消費者客戶端)特定彈性應用
我有控制器服務JSON數據消費者客戶端應用程序。
ExampleController.groovy
class ExampleCotnroller {
def endpointServerJosn(){
}
}
最近引入一個更多的消費者,並預計類似的JSON數據,但來自不同的來源。
所以我加了一個標誌,我application.yml another.client =真和修改我的控制器:
更新ExampleController.groovy
class ExampleCotnroller {
def endpointServerJosn(){
if(another.client){
//server data from this client's source
}else{
//server data from other client's source
}
}
}
但我期待更多的設置的客戶和這將弄亂我的控制器,因爲我沒有找到我的解決方案可擴展的設計。這裏每個客戶端都有自己的從屬API控制器來獲取數據。
客戶機1發送請求 - >主(我的控制器)攔截,調用相關的客戶端一個 礦石多個從屬的API,取出數據並聚集它 併發送回數據
simiallarly,客戶機2發送請求 - >主(我的控制器) 攔截,調用一個或相關客戶端以上從屬的API 2
我想具有抽象控制器等:
class AbstractApplicationController{
def endpointServerJson();
}
class FirstCilentController extends AbstractApplicationController {
}
class SecondClientController extends AbstractApplicationController {
}
以上設計是否可以實現可擴展的解決方案?應用程序可以根據外部yml或application.yml文件中的配置選擇要使用哪個控制器?