Skip to content
Advertisement

Developing multiple springboot services in an IDE

How can you develop and test multiple REST services developed in Springboot from an IDE? I will have to have different port numbers for each REST service, is there any better way?

Advertisement

Answer

First of all you’ll probably want to show all the source files from all the services in the same IntelliJ project.

So you’ll need to maintain a special file (assuming you have maven) that will “aggregate” all the modules:

<project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yourorg</groupId>
    <artifactId>yourproject</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <modules>
        <module>microservice1</module>
        <module>microservice2</module>
        ...
    </modules>
</project>

Now indeed if you’ll run all service with the default configurations the web ports will clash, so you’ll have to provide some kind of mappings. There are many ways to do so. You can create a special profile with “altered” configurations for the ports. For example, create application-local.yaml next to application.yaml:

// application.yaml
server:
   port: 8080
// application-local.yaml
server:
   port: 9999

And start the application with the active profile “local”. Spring will have two different configurations and will pick a “more specific” local profile (custom profiles will always override the configurations specified in the default application.yml).

This is only one possible way (not necessarily the best one), but in general, different configurations must be provided for the local and regular environments.

To pick the way that will work for you in the best possible way, check out the externalized configuration guide of spring boot

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement