Working with multiple dispatcher servlets in a spring application

后端 未结 3 976
心在旅途
心在旅途 2021-02-09 14:18

In my spring application, I have the following configuration classes for the spring environment:

WebAppInitializer.java

@Order(value=1)
         


        
3条回答
  •  逝去的感伤
    2021-02-09 15:02

    You can have as many DispatcherServlets as you want. Basically what you need to do is duplicate the configuration and give the servlet a different name (else it will overwrite the previous one), and have some separate configuration classes (or xml files) for it.

    Your controllers shouldn't care in which DispatcherServlet they run neither should you include code to detect that (what if you add another, and another you would need to keep modifying your controllers to fix that).

    However while you can have multiple servlets in general there isn't much need for multiple servlets and you can handle it with a single instance of the DispatcherServlet.

提交回复
热议问题