Deploying Spring Boot on an Intranet

1. Prepare the environment

Make sure the server or machine on the intranet has the basic environment needed to run a Spring Boot application:

  • JDK: make sure the server has a suitable version of the JDK installed (Java 8 or above is usually recommended).
  • Maven/Gradle: install Maven or Gradle depending on the build tool your project uses.
  • Database: if the application needs to connect to a database, make sure the database is reachable from the intranet and that the connection configuration is correct.

2. Compile the Spring Boot application

First, you need to compile your Spring Boot application to produce an executable JAR file. You can run the following commands in the project directory:

  • Maven build command:
1
2
mvn clean package

  • Gradle build command:
1
./gradlew build

This generates an executable JAR file in the target/ or build/libs/ directory, usually named your-application-name.jar.

3. Transfer the JAR to the intranet server

Upload the generated JAR file to the target server on the intranet. You can use any of various file transfer tools, for example:

  • SCP (if the server supports SSH):
1
scp your-application-name.jar user@server-ip:/path/to/deploy/
  • FTP or SFTP (if an FTP service is configured).

4. Configure the Spring Boot application

When deploying on an intranet, you may need to modify the configuration file according to the environment, such as application.properties or application.yml. Common configuration items include:

  • Database connection information (spring.datasource.url, spring.datasource.username, etc.).
  • Logging configuration.
  • Service port (server.port).
  • Security settings (such as disabling external access, or setting an access whitelist).

For example, modifying the database configuration in application.properties:

1
2
3
spring.datasource.url=jdbc:mysql://localhost:3306/your_db
spring.datasource.username=db_user
spring.datasource.password=db_password

5. Start the Spring Boot application

On the intranet server, start the Spring Boot application with the following command:

1
java -jar your-application-name.jar

If you want the application to run in the background, you can use nohup or a similar tool:

1
nohup java -jar your-application-name.jar > output.log 2>&1 &

This redirects the output to the output.log file and lets the application run in the background.

6. Configure the firewall and network

  • Make sure the server’s firewall allows access to the port the application is bound to (8080 by default). If you use a different port, configure the firewall to allow access to that port.
  • If the Spring Boot application needs to be accessed through a specific IP address or domain name on the intranet, make sure the DNS or hosts configuration is correct.

7. Monitoring and logging

  • Logging: a Spring Boot application outputs logs to the console; you can configure logging to write to a file for persistent storage. A common approach is to set the log path in application.properties or application.yml:
1
logging.file.name=/path/to/logs/application.log
  • Monitoring: you can use Spring Boot’s Actuator or other monitoring tools (such as Prometheus and Grafana) to monitor the application’s running status.

8. Set up startup on boot (optional)

If you want the application to start automatically when the server reboots, you can use systemd (on Linux systems) or configure it as a Windows service.

Linux systems (Systemd)

Create a systemd service file, such as /etc/systemd/system/yourapp.service:

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Spring Boot Application
After=network.target

[Service]
User=your_user
ExecStart=/usr/bin/java -jar /path/to/your-application-name.jar
SuccessExitStatus=143
Restart=always

[Install]
WantedBy=multi-user.target

Then enable and start the service:

1
2
sudo systemctl enable yourapp
sudo systemctl start yourapp