Configure Spring Boot on Elastic Beanstalk¶
This tutorial covers the main configuration layers for Spring Boot on Elastic Beanstalk: application properties, environment properties, Procfile, and .ebextensions. The objective is to make runtime settings explicit, source-controlled, and repeatable across environments.
Prerequisites¶
- Running Java Elastic Beanstalk environment.
- Spring Boot app deployed once successfully.
- Familiarity with Maven packaging and the
PORTcontract.
What You'll Build¶
You will build:
- Environment-property driven application configuration.
- A source-controlled health check and JVM tuning baseline.
- A
Procfilestartup contract for the JAR.
flowchart TD
A[application.properties] --> D[Spring Environment]
B[EB Environment Properties] --> D
C[.ebextensions option_settings] --> E[Elastic Beanstalk Platform]
E --> F[nginx plus Java Process]
D --> F
G[Procfile] --> F Steps¶
- Keep port binding inside
application.properties.
server.port=${PORT:5000}
spring.application.name=aws-eb-java-reference
logging.level.root=${LOG_LEVEL:INFO}
app.environment=${ENV_NAME:local}
- Set runtime environment properties through Elastic Beanstalk.
- Read those values in Spring Boot.
package com.example.guide.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConfigController {
@Value("${app.environment:local}")
private String environment;
@GetMapping("/demo/config")
public Map<String, String> config() {
return Map.of("environment", environment);
}
}
- Keep the startup command in
Procfile.
- Add a health check path and JVM options with
.ebextensions.
option_settings:
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: /health
aws:elasticbeanstalk:container:java:jvmoptions:
Xms: 256m
Xmx: 512m
XX: +UseG1GC
- Add an environment file for a larger example.
option_settings:
aws:elasticbeanstalk:application:environment:
SPRING_PROFILES_ACTIVE: prod
SERVER_FORWARD_HEADERS_STRATEGY: framework
- Redeploy configuration changes.
Verification¶
Use these checks after applying configuration:
Expected outcomes:
- Environment properties are visible in Elastic Beanstalk.
- The app reads expected values without hardcoding secrets.
/healthremains the configured health check path.- JVM settings are captured in source-controlled config files.