1. Preparation
Use Idea to build a hello world Spring Boot project.
Development environment description:
(1) Spring Boot 2.7.0
(2) Idea: IntelliJ IDEA 2022.2.2
(3) OS : Mac OS
The environment is different, some operations are slightly different, but the overall idea is the same.
2. Start multiple SpringBoot
2.1 Solution 1: Modify the port of the configuration file
In the Spring Boot project, the port number can be configured in the configuration file, so the final The simple solution that can be thought of is to modify the port configuration server.port in the configuration file application.(properties/yml). The specific operations are:
(1) First configure server.port = 8080, and run the startup class to start the application.
(2) Modify server.port = 8081 and run the startup class to start the application.
This will start two Spring Boot applications with different ports. Although this method is simple, its operation experience is not friendly, and modifying the configuration file in an actual project will definitely not work.
2.2 Solution 2: Edit Configurations of Idea tool
Use the Edit Configurations provided by Idea to configure application parameters.
Click Modify Options to add application parameters:
The interface may be slightly different depending on the version of the development tool. , but you can all find Program arguments:
Description:
(1) VM options: VM options is actually the runtime environment we need in the program Variable, it needs to start with -D or -X or -XX, each parameter is separated by a space eg: -Dspring.profiles.active=dev
(2) Program arguments: Program arguments are passed into main for us String array args[] of the method, which usually starts with --, such as --spring.profiles.active=dev; which is equivalent to -Dspring.profiles.active=dev. If both exist, the Program arguments configuration takes precedence.
Then add a --server.port=8081 configuration:
2.3 Solution 3: Use RunDashboard
IDEA provides powerful Dashboard functionality (Run Dashboard) can manage the above multi-application startup instances very well, visualize the projects we configure, facilitate the reconfiguration, Run, and Debug of the spring boot project, and simplify our operation steps.
Add the following configuration in the .idea/workspace.xml file:
<component name="RunDashboard"> <option name="configurationTypes"> <set> <option value="SpringBootApplicationConfigurationType" /> </set> </option> </component>
After starting again, you can see the Run Dashboard at the bottom
You can copy a configuration here:
In this way, you can start multiple ones:
3. Two Spring Boot startups on the same port
SpringBoot comes with Tomcat, just run SpringApplication.run in the main method directly, and it is not required for access With project name.
If there are two SpringBoot projects in the idea and the access paths of the controller layer are the same, and since there is no path name, two main methods cannot be run at the same time. If two main methods are run at the same time, the port number must be occupied. How to start two projects at the same time.
You only need to deploy the war package to the Tomcat server, and there is no need to use SpringBoot's built-in Tomcat server. To access, just enter localhost:8080/project name/path in the URL. In the development tools, you can also use external Tomcat to start.
The above is the detailed content of Idea how to start multiple SpringBoot projects. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use