20

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?

1
  • 2
    Did you ever figure this out? I'm facing the exact same issue. Commented Feb 15, 2016 at 22:40

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

4 Comments

that good to know, but i would like to start them on the same port but different contextPaths.
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
@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
@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...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.