简体   繁体   English

在 IDE 中开发多个 springboot 服务

[英]Developing multiple springboot services in an IDE

How can you develop and test multiple REST services developed in Springboot from an IDE?如何从 IDE 开发和测试 Springboot 中开发的多个 REST 服务? I will have to have different port numbers for each REST service, is there any better way?我必须为每个 REST 服务设置不同的端口号,有没有更好的方法?

First of all you'll probably want to show all the source files from all the services in the same IntelliJ project.首先,您可能希望显示来自同一个 IntelliJ 项目中所有服务的所有源文件。

So you'll need to maintain a special file (assuming you have maven) that will "aggregate" all the modules:所以你需要维护一个特殊的文件(假设你有 maven),它将“聚合”所有模块:

<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.现在确实,如果您使用默认配置运行所有服务,web 端口将发生冲突,因此您必须提供某种映射。 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 旁边创建application.yaml application-local.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 configuration and will pick "more specific" local profile (custom profiles will always override the configurations specified in the default application.yaml ). Spring 将有两种不同的配置,并将选择“更具体”的本地配置文件(自定义配置文件将始终覆盖默认application.yaml中指定的配置。yaml)。

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要选择最适合您的方式,请查看 spring 引导的外部化配置指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM