How to define isolated web contexts in a modular Spring Boot application?What's the point of Spring MVC's DelegatingFilterProxy?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Spring-MVC: What are a “context” and “namespace”?Query Regarding application context in springHow to configure port for a Spring Boot applicationSpring Boot SOAP webservice with MVCMultipart with Spring Boot Rest ServiceHow exactly are the root context and the dispatcher servlet context into a Spring MVC web application?Need help converting from web.xml spring bootSpring Boot creating multiple (functioning) webmvc applications using auto configuration

Which ping implementation is cygwin using?

What is going on: C++ std::move on std::shared_ptr increases use_count?

How do I politely hint customers to leave my store, without pretending to need leave store myself?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

What are the advantages and disadvantages of Preprints.org compared with arXiv?

How can I fix a framing mistake so I can drywall?

Why should I always enable compiler warnings?

How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?

Job offer without any details but asking me to withdraw other applications - is it normal?

RP Automatic Updates

How can "life" insurance prevent the cheapening of death?

Are there any instances of members of different Hogwarts houses coupling up and marrying each other?

SQL Server table with 4,000,000 rows is 40GB

When did computers stop checking memory on boot?

Why was "leaping into the river" a valid trial outcome to prove one's innocence?

Is BitLocker useful in the case of stolen laptop?

Have there been any countries that voted themselves out of existence?

Are there take-over requests from autopilots?

Does the mana ability restriction of Pithing Needle refer to the cost or the effect of an activated ability?

Are Democrats more likely to believe Astrology is a science?

Is there a "right" way to interpret a novel? If so, how do we make sure our novel is interpreted correctly?

Awesomism and its awesome gods

Is there a standard terminology for female equivalents of terms such as 'Kingdom' and if so, what are the most common terms?

Are programming languages necessary/useful for operations research practitioner?



How to define isolated web contexts in a modular Spring Boot application?


What's the point of Spring MVC's DelegatingFilterProxy?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Spring-MVC: What are a “context” and “namespace”?Query Regarding application context in springHow to configure port for a Spring Boot applicationSpring Boot SOAP webservice with MVCMultipart with Spring Boot Rest ServiceHow exactly are the root context and the dispatcher servlet context into a Spring MVC web application?Need help converting from web.xml spring bootSpring Boot creating multiple (functioning) webmvc applications using auto configuration






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








8















Given a Spring Boot application comprised of a bootstrap module, and two or more isolated business modules - each of which exposes REST API specific to a business domain, and each of which uses an independent, isolated document store for data persistence, how do I go about configuring such an application, such that:



  • The bootstrap module defines a parent context (non-web) which provides certain shared resources to underlying modules (global config, object mappers, etc.)

  • Each business module exposes their REST controllers on the same port but using a different context path. Ideally, I want to be able to define a base path for each module (e.g. /api/catalog, /api/orders) and separately define the sub-path within each controller.

  • Each business module defines its own repository configuration (e.g. different MongoDB settings for each module)

In order to isolate the contexts of the individual business modules (which allows me to manage independent repository configurations in each module) I have tried using the context hierarchies available in SpringApplicationBuilder to isolate the contexts of each of the individual business modules:



public class Application 

@Configuration
protected static class ParentContext


public static void main(String[] args) throws Exception
new SpringApplicationBuilder(ParentContext.class)
.child(products.config.ModuleConfiguration.class)
.web(true)
.sibling(orders.config.ModuleConfiguration.class)
.web(true)
.run(args);




however as each module contains a configuration class annotated with @EnableAutoConfiguration this causes Spring Boot to attempt to launch two independent embedded servlet containers, each trying to bind to the same port:



@Configuration
@EnableAutoConfiguration
public class WebApplicationConfiguration

@Value("$api.basePath:/api")
protected String apiBasePath;

@Bean
public DispatcherServlet dispatcherServlet()
return new DispatcherServlet();


@Bean
public ServletRegistrationBean dispatcherServletRegistration()
ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(),
apiBasePath + "/products/*");
registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);

return registration;




The Spring Boot documentation on context hierarchies states that the parent context cannot be a web context, so I'm a bit lost as to how I can share an embedded servlet container between isolated child contexts.



I have created a minimal GitHub project to illustrate the point:










share|improve this question
































    8















    Given a Spring Boot application comprised of a bootstrap module, and two or more isolated business modules - each of which exposes REST API specific to a business domain, and each of which uses an independent, isolated document store for data persistence, how do I go about configuring such an application, such that:



    • The bootstrap module defines a parent context (non-web) which provides certain shared resources to underlying modules (global config, object mappers, etc.)

    • Each business module exposes their REST controllers on the same port but using a different context path. Ideally, I want to be able to define a base path for each module (e.g. /api/catalog, /api/orders) and separately define the sub-path within each controller.

    • Each business module defines its own repository configuration (e.g. different MongoDB settings for each module)

    In order to isolate the contexts of the individual business modules (which allows me to manage independent repository configurations in each module) I have tried using the context hierarchies available in SpringApplicationBuilder to isolate the contexts of each of the individual business modules:



    public class Application 

    @Configuration
    protected static class ParentContext


    public static void main(String[] args) throws Exception
    new SpringApplicationBuilder(ParentContext.class)
    .child(products.config.ModuleConfiguration.class)
    .web(true)
    .sibling(orders.config.ModuleConfiguration.class)
    .web(true)
    .run(args);




    however as each module contains a configuration class annotated with @EnableAutoConfiguration this causes Spring Boot to attempt to launch two independent embedded servlet containers, each trying to bind to the same port:



    @Configuration
    @EnableAutoConfiguration
    public class WebApplicationConfiguration

    @Value("$api.basePath:/api")
    protected String apiBasePath;

    @Bean
    public DispatcherServlet dispatcherServlet()
    return new DispatcherServlet();


    @Bean
    public ServletRegistrationBean dispatcherServletRegistration()
    ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(),
    apiBasePath + "/products/*");
    registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);

    return registration;




    The Spring Boot documentation on context hierarchies states that the parent context cannot be a web context, so I'm a bit lost as to how I can share an embedded servlet container between isolated child contexts.



    I have created a minimal GitHub project to illustrate the point:










    share|improve this question




























      8












      8








      8








      Given a Spring Boot application comprised of a bootstrap module, and two or more isolated business modules - each of which exposes REST API specific to a business domain, and each of which uses an independent, isolated document store for data persistence, how do I go about configuring such an application, such that:



      • The bootstrap module defines a parent context (non-web) which provides certain shared resources to underlying modules (global config, object mappers, etc.)

      • Each business module exposes their REST controllers on the same port but using a different context path. Ideally, I want to be able to define a base path for each module (e.g. /api/catalog, /api/orders) and separately define the sub-path within each controller.

      • Each business module defines its own repository configuration (e.g. different MongoDB settings for each module)

      In order to isolate the contexts of the individual business modules (which allows me to manage independent repository configurations in each module) I have tried using the context hierarchies available in SpringApplicationBuilder to isolate the contexts of each of the individual business modules:



      public class Application 

      @Configuration
      protected static class ParentContext


      public static void main(String[] args) throws Exception
      new SpringApplicationBuilder(ParentContext.class)
      .child(products.config.ModuleConfiguration.class)
      .web(true)
      .sibling(orders.config.ModuleConfiguration.class)
      .web(true)
      .run(args);




      however as each module contains a configuration class annotated with @EnableAutoConfiguration this causes Spring Boot to attempt to launch two independent embedded servlet containers, each trying to bind to the same port:



      @Configuration
      @EnableAutoConfiguration
      public class WebApplicationConfiguration

      @Value("$api.basePath:/api")
      protected String apiBasePath;

      @Bean
      public DispatcherServlet dispatcherServlet()
      return new DispatcherServlet();


      @Bean
      public ServletRegistrationBean dispatcherServletRegistration()
      ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(),
      apiBasePath + "/products/*");
      registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);

      return registration;




      The Spring Boot documentation on context hierarchies states that the parent context cannot be a web context, so I'm a bit lost as to how I can share an embedded servlet container between isolated child contexts.



      I have created a minimal GitHub project to illustrate the point:










      share|improve this question
















      Given a Spring Boot application comprised of a bootstrap module, and two or more isolated business modules - each of which exposes REST API specific to a business domain, and each of which uses an independent, isolated document store for data persistence, how do I go about configuring such an application, such that:



      • The bootstrap module defines a parent context (non-web) which provides certain shared resources to underlying modules (global config, object mappers, etc.)

      • Each business module exposes their REST controllers on the same port but using a different context path. Ideally, I want to be able to define a base path for each module (e.g. /api/catalog, /api/orders) and separately define the sub-path within each controller.

      • Each business module defines its own repository configuration (e.g. different MongoDB settings for each module)

      In order to isolate the contexts of the individual business modules (which allows me to manage independent repository configurations in each module) I have tried using the context hierarchies available in SpringApplicationBuilder to isolate the contexts of each of the individual business modules:



      public class Application 

      @Configuration
      protected static class ParentContext


      public static void main(String[] args) throws Exception
      new SpringApplicationBuilder(ParentContext.class)
      .child(products.config.ModuleConfiguration.class)
      .web(true)
      .sibling(orders.config.ModuleConfiguration.class)
      .web(true)
      .run(args);




      however as each module contains a configuration class annotated with @EnableAutoConfiguration this causes Spring Boot to attempt to launch two independent embedded servlet containers, each trying to bind to the same port:



      @Configuration
      @EnableAutoConfiguration
      public class WebApplicationConfiguration

      @Value("$api.basePath:/api")
      protected String apiBasePath;

      @Bean
      public DispatcherServlet dispatcherServlet()
      return new DispatcherServlet();


      @Bean
      public ServletRegistrationBean dispatcherServletRegistration()
      ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(),
      apiBasePath + "/products/*");
      registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);

      return registration;




      The Spring Boot documentation on context hierarchies states that the parent context cannot be a web context, so I'm a bit lost as to how I can share an embedded servlet container between isolated child contexts.



      I have created a minimal GitHub project to illustrate the point:







      spring-mvc spring-boot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 7:54









      M-Razavi

      1,8271 gold badge24 silver badges34 bronze badges




      1,8271 gold badge24 silver badges34 bronze badges










      asked Jun 6 '16 at 14:07









      tarnationtarnation

      413 bronze badges




      413 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0

















          • Create configuration class for business module child1's context



            package com.child1;
            @Configuration
            @ComponentScan(basePackages = "com.child1a", "com.child1b")
            public class Child1Configuration




          • Create configuration class for business module child2's context



            package com.child2;
            @Configuration
            @ComponentScan(basePackages = "com.child2a", "com.child2b")
            public class Child2Configuration





          • Create a configuration class for bootstrap module parent context. Specify the component scanning for beans to be shared by child contexts



            package com.parent;
            @Configuration
            @ComponentScan(basePackages = "com.parent1", "com.root")
            public class ParentConfiguration





          • Create SpringBootApplication class with two dispatcher servlets beans, one for each business module. Create application context for each servlet and set the context created by the boot application as root. Basically spring will inject the context into the ApplicationContext parameter of the @Bean methods.



            package com.parent;
            @SpringBootApplication
            public class Application

            public static void main(String[] args)
            ApplicationContext context = SpringApplication.run(Application.class, args);


            @Bean
            public ServletRegistrationBean child1(ApplicationContext parentContext)

            DispatcherServlet dispatcherServlet = new DispatcherServlet();
            dispatcherServlet.setDetectAllHandlerMappings(false);

            AnnotationConfigWebApplicationContext applicationContext = new
            AnnotationConfigWebApplicationContext();
            applicationContext.setParent(parentContext);
            applicationContext.register(Child1Configuration.class);

            applicationContext.refresh();

            dispatcherServlet.setApplicationContext(applicationContext);

            ServletRegistrationBean servletRegistrationBean = new
            ServletRegistrationBean(dispatcherServlet, true, "/child1/*");

            servletRegistrationBean.setName("child1");

            servletRegistrationBean.setLoadOnStartup(1);

            return servletRegistrationBean;


            @Bean
            public ServletRegistrationBean child2(ApplicationContext parentContext)



            DispatcherServlet dispatcherServlet = new DispatcherServlet();
            dispatcherServlet.setDetectAllHandlerMappings(false);

            AnnotationConfigWebApplicationContext applicationContext = new
            AnnotationConfigWebApplicationContext();
            applicationContext.setParent(parentContext);

            applicationContext.register(Child2Configuration.class);

            applicationContext.refresh();

            dispatcherServlet.setApplicationContext(applicationContext);

            ServletRegistrationBean servletRegistrationBean = new
            ServletRegistrationBean(dispatcherServlet, true, "/child2/*");

            servletRegistrationBean.setName("child2");

            servletRegistrationBean.setLoadOnStartup(1);

            return servletRegistrationBean;








          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37659608%2fhow-to-define-isolated-web-contexts-in-a-modular-spring-boot-application%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0

















            • Create configuration class for business module child1's context



              package com.child1;
              @Configuration
              @ComponentScan(basePackages = "com.child1a", "com.child1b")
              public class Child1Configuration




            • Create configuration class for business module child2's context



              package com.child2;
              @Configuration
              @ComponentScan(basePackages = "com.child2a", "com.child2b")
              public class Child2Configuration





            • Create a configuration class for bootstrap module parent context. Specify the component scanning for beans to be shared by child contexts



              package com.parent;
              @Configuration
              @ComponentScan(basePackages = "com.parent1", "com.root")
              public class ParentConfiguration





            • Create SpringBootApplication class with two dispatcher servlets beans, one for each business module. Create application context for each servlet and set the context created by the boot application as root. Basically spring will inject the context into the ApplicationContext parameter of the @Bean methods.



              package com.parent;
              @SpringBootApplication
              public class Application

              public static void main(String[] args)
              ApplicationContext context = SpringApplication.run(Application.class, args);


              @Bean
              public ServletRegistrationBean child1(ApplicationContext parentContext)

              DispatcherServlet dispatcherServlet = new DispatcherServlet();
              dispatcherServlet.setDetectAllHandlerMappings(false);

              AnnotationConfigWebApplicationContext applicationContext = new
              AnnotationConfigWebApplicationContext();
              applicationContext.setParent(parentContext);
              applicationContext.register(Child1Configuration.class);

              applicationContext.refresh();

              dispatcherServlet.setApplicationContext(applicationContext);

              ServletRegistrationBean servletRegistrationBean = new
              ServletRegistrationBean(dispatcherServlet, true, "/child1/*");

              servletRegistrationBean.setName("child1");

              servletRegistrationBean.setLoadOnStartup(1);

              return servletRegistrationBean;


              @Bean
              public ServletRegistrationBean child2(ApplicationContext parentContext)



              DispatcherServlet dispatcherServlet = new DispatcherServlet();
              dispatcherServlet.setDetectAllHandlerMappings(false);

              AnnotationConfigWebApplicationContext applicationContext = new
              AnnotationConfigWebApplicationContext();
              applicationContext.setParent(parentContext);

              applicationContext.register(Child2Configuration.class);

              applicationContext.refresh();

              dispatcherServlet.setApplicationContext(applicationContext);

              ServletRegistrationBean servletRegistrationBean = new
              ServletRegistrationBean(dispatcherServlet, true, "/child2/*");

              servletRegistrationBean.setName("child2");

              servletRegistrationBean.setLoadOnStartup(1);

              return servletRegistrationBean;








            share|improve this answer





























              0

















              • Create configuration class for business module child1's context



                package com.child1;
                @Configuration
                @ComponentScan(basePackages = "com.child1a", "com.child1b")
                public class Child1Configuration




              • Create configuration class for business module child2's context



                package com.child2;
                @Configuration
                @ComponentScan(basePackages = "com.child2a", "com.child2b")
                public class Child2Configuration





              • Create a configuration class for bootstrap module parent context. Specify the component scanning for beans to be shared by child contexts



                package com.parent;
                @Configuration
                @ComponentScan(basePackages = "com.parent1", "com.root")
                public class ParentConfiguration





              • Create SpringBootApplication class with two dispatcher servlets beans, one for each business module. Create application context for each servlet and set the context created by the boot application as root. Basically spring will inject the context into the ApplicationContext parameter of the @Bean methods.



                package com.parent;
                @SpringBootApplication
                public class Application

                public static void main(String[] args)
                ApplicationContext context = SpringApplication.run(Application.class, args);


                @Bean
                public ServletRegistrationBean child1(ApplicationContext parentContext)

                DispatcherServlet dispatcherServlet = new DispatcherServlet();
                dispatcherServlet.setDetectAllHandlerMappings(false);

                AnnotationConfigWebApplicationContext applicationContext = new
                AnnotationConfigWebApplicationContext();
                applicationContext.setParent(parentContext);
                applicationContext.register(Child1Configuration.class);

                applicationContext.refresh();

                dispatcherServlet.setApplicationContext(applicationContext);

                ServletRegistrationBean servletRegistrationBean = new
                ServletRegistrationBean(dispatcherServlet, true, "/child1/*");

                servletRegistrationBean.setName("child1");

                servletRegistrationBean.setLoadOnStartup(1);

                return servletRegistrationBean;


                @Bean
                public ServletRegistrationBean child2(ApplicationContext parentContext)



                DispatcherServlet dispatcherServlet = new DispatcherServlet();
                dispatcherServlet.setDetectAllHandlerMappings(false);

                AnnotationConfigWebApplicationContext applicationContext = new
                AnnotationConfigWebApplicationContext();
                applicationContext.setParent(parentContext);

                applicationContext.register(Child2Configuration.class);

                applicationContext.refresh();

                dispatcherServlet.setApplicationContext(applicationContext);

                ServletRegistrationBean servletRegistrationBean = new
                ServletRegistrationBean(dispatcherServlet, true, "/child2/*");

                servletRegistrationBean.setName("child2");

                servletRegistrationBean.setLoadOnStartup(1);

                return servletRegistrationBean;








              share|improve this answer



























                0














                0










                0










                • Create configuration class for business module child1's context



                  package com.child1;
                  @Configuration
                  @ComponentScan(basePackages = "com.child1a", "com.child1b")
                  public class Child1Configuration




                • Create configuration class for business module child2's context



                  package com.child2;
                  @Configuration
                  @ComponentScan(basePackages = "com.child2a", "com.child2b")
                  public class Child2Configuration





                • Create a configuration class for bootstrap module parent context. Specify the component scanning for beans to be shared by child contexts



                  package com.parent;
                  @Configuration
                  @ComponentScan(basePackages = "com.parent1", "com.root")
                  public class ParentConfiguration





                • Create SpringBootApplication class with two dispatcher servlets beans, one for each business module. Create application context for each servlet and set the context created by the boot application as root. Basically spring will inject the context into the ApplicationContext parameter of the @Bean methods.



                  package com.parent;
                  @SpringBootApplication
                  public class Application

                  public static void main(String[] args)
                  ApplicationContext context = SpringApplication.run(Application.class, args);


                  @Bean
                  public ServletRegistrationBean child1(ApplicationContext parentContext)

                  DispatcherServlet dispatcherServlet = new DispatcherServlet();
                  dispatcherServlet.setDetectAllHandlerMappings(false);

                  AnnotationConfigWebApplicationContext applicationContext = new
                  AnnotationConfigWebApplicationContext();
                  applicationContext.setParent(parentContext);
                  applicationContext.register(Child1Configuration.class);

                  applicationContext.refresh();

                  dispatcherServlet.setApplicationContext(applicationContext);

                  ServletRegistrationBean servletRegistrationBean = new
                  ServletRegistrationBean(dispatcherServlet, true, "/child1/*");

                  servletRegistrationBean.setName("child1");

                  servletRegistrationBean.setLoadOnStartup(1);

                  return servletRegistrationBean;


                  @Bean
                  public ServletRegistrationBean child2(ApplicationContext parentContext)



                  DispatcherServlet dispatcherServlet = new DispatcherServlet();
                  dispatcherServlet.setDetectAllHandlerMappings(false);

                  AnnotationConfigWebApplicationContext applicationContext = new
                  AnnotationConfigWebApplicationContext();
                  applicationContext.setParent(parentContext);

                  applicationContext.register(Child2Configuration.class);

                  applicationContext.refresh();

                  dispatcherServlet.setApplicationContext(applicationContext);

                  ServletRegistrationBean servletRegistrationBean = new
                  ServletRegistrationBean(dispatcherServlet, true, "/child2/*");

                  servletRegistrationBean.setName("child2");

                  servletRegistrationBean.setLoadOnStartup(1);

                  return servletRegistrationBean;








                share|improve this answer














                • Create configuration class for business module child1's context



                  package com.child1;
                  @Configuration
                  @ComponentScan(basePackages = "com.child1a", "com.child1b")
                  public class Child1Configuration




                • Create configuration class for business module child2's context



                  package com.child2;
                  @Configuration
                  @ComponentScan(basePackages = "com.child2a", "com.child2b")
                  public class Child2Configuration





                • Create a configuration class for bootstrap module parent context. Specify the component scanning for beans to be shared by child contexts



                  package com.parent;
                  @Configuration
                  @ComponentScan(basePackages = "com.parent1", "com.root")
                  public class ParentConfiguration





                • Create SpringBootApplication class with two dispatcher servlets beans, one for each business module. Create application context for each servlet and set the context created by the boot application as root. Basically spring will inject the context into the ApplicationContext parameter of the @Bean methods.



                  package com.parent;
                  @SpringBootApplication
                  public class Application

                  public static void main(String[] args)
                  ApplicationContext context = SpringApplication.run(Application.class, args);


                  @Bean
                  public ServletRegistrationBean child1(ApplicationContext parentContext)

                  DispatcherServlet dispatcherServlet = new DispatcherServlet();
                  dispatcherServlet.setDetectAllHandlerMappings(false);

                  AnnotationConfigWebApplicationContext applicationContext = new
                  AnnotationConfigWebApplicationContext();
                  applicationContext.setParent(parentContext);
                  applicationContext.register(Child1Configuration.class);

                  applicationContext.refresh();

                  dispatcherServlet.setApplicationContext(applicationContext);

                  ServletRegistrationBean servletRegistrationBean = new
                  ServletRegistrationBean(dispatcherServlet, true, "/child1/*");

                  servletRegistrationBean.setName("child1");

                  servletRegistrationBean.setLoadOnStartup(1);

                  return servletRegistrationBean;


                  @Bean
                  public ServletRegistrationBean child2(ApplicationContext parentContext)



                  DispatcherServlet dispatcherServlet = new DispatcherServlet();
                  dispatcherServlet.setDetectAllHandlerMappings(false);

                  AnnotationConfigWebApplicationContext applicationContext = new
                  AnnotationConfigWebApplicationContext();
                  applicationContext.setParent(parentContext);

                  applicationContext.register(Child2Configuration.class);

                  applicationContext.refresh();

                  dispatcherServlet.setApplicationContext(applicationContext);

                  ServletRegistrationBean servletRegistrationBean = new
                  ServletRegistrationBean(dispatcherServlet, true, "/child2/*");

                  servletRegistrationBean.setName("child2");

                  servletRegistrationBean.setLoadOnStartup(1);

                  return servletRegistrationBean;









                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 1 at 18:53









                gsharmagsharma

                11 bronze badge




                11 bronze badge





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37659608%2fhow-to-define-isolated-web-contexts-in-a-modular-spring-boot-application%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript