18

I would like to be able to have multiple web apps sharing a domain project and running under different contextPaths.

By setting server.contextPath=/webshop in a spring boot app I dont need to prefix all the RequestMappings.

I would like the webshop, admin, and main page to share a common domain project which contains all the entities and common services.

Maybe with something like?

public static void main(String[] args) {
    new SpringApplicationBuilder(Domain.class)
        .showBanner(false)
        .child(Admin.class, Webshop.class)
        .run(args);
}

My problem is how do I start a spring boot app with a common domain model, and then a couple of stand alone web apps with unique contextPaths?

Leon Radley
  • 7,596
  • 5
  • 35
  • 54

1 Answers1

10

Like this for example:

public static void main(String[] args) {
    start(Admin.class, Webshop.class).run(args);
    start(Another.class).properties("server.port=${other.port:9000}").run(args);
}

private static SpringApplicationBuilder start(Class<?>... sources) {
    return new SpringApplicationBuilder(Domain.class)
        .showBanner(false)
        .child(sources);
}

It would start two apps on different ports.

Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • 6
    that good to know, but i would like to start them on the same port but different contextPaths. – Leon Radley Sep 16 '14 at 13:36
  • 9
    That approach contradict with original boot architecturial desing: it is intended first of all for quick development of microservices. So it is inteded single context for single app. I guess you don't want to deal with single context in which as client as admin tasks are performed, and solving complex security issues. So my advise: simply create 2, or 3 apps using spring boot. Deploy them to docker, and create a docker container of apache or nginx, or any other, which will be proxying the requests based on context path to correct web app. And this will be like it was intended by springboot – Ilya Dyoshin Feb 05 '17 at 11:26
  • 1
    @IlyaDyoshin I like what you suggested above, do you know of any simple hello world example showing how you would break a complex app to 2-3 dockerzed apps – Mo Hassan May 30 '17 at 14:47
  • 1
    @MoHassan there would not be any tutorial: it is up to you first of all to cut your application in subsystems, which could operate separately. Then you start to separate them. also remember that in contrast to single large application where you can keep DRY principle, in microservices world you will be WET (writting everything twice): one part for microservice, another for client part of microservice. After that you can establish an eureka server (have a look at spring's tutorials), and then run all this in docker with compose... – Ilya Dyoshin May 30 '17 at 19:33