簡體   English   中英

動態創建Spring Boot RestController

[英]Create Spring Boot RestController dynamically

我需要在Spring Boot應用程序中動態創建一個Rest端點。 有沒有一種方法可以在運行時實例化並激活Rest服務,而不是使用@RestController靜態創建類? 在運行時可以指定端點,輸入參數等。

也有一些Groovy選項嗎?

謝謝,Sandeep約瑟夫

我認為采取的方法是創建一個自定義MvcEndpoint,該MvcEndpoint將處理特定路徑上的所有請求,從那里開始,具體取決於您可以處理請求的內部配置。 它基本上只是一個Servlet(這也是一個選擇)。 您完全可以控制該請求。

public class MyEndpoint extends AbstractMvcEndpoint 
// can optionally implements ApplicationContextAware, ServletContextAware
// to inject configuration, etc.
{
    @RequestMapping("/dynamic-enpoints-prefix/**")
    public ModelAndView handle(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
      // here you have the request and response. Can do anything.
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM