Introduction
Lately I was working on a Micro-service based on Spring Boot
. I deployed the Micro-service onto AWS Elastic Beanstalk
, like I’ve done it a few hundred times with other apps, but this time the Micro-service was unable to start. Tomcat was giving me the cold shoulder with 404
s. A look into the logs showed me, that the JDBC_CONNECTION_STRING
was not set in the environment, even if it was set in the Environment Properties
on the configuration page in AWS Elastic Beanstalk
.
The Problem
Analyzing the problem by comparing the version (64bit Amazon Linux 2017.09 v2.7.0 running Tomcat 8 Java 8
) - on which the new app was running - against other instances (64bit Amazon Linux 2015.03 v2.0.1 running Tomcat 8 Java 8
), revealed that the environment settings are handled differently:
- The older version was handling them as you would expect it. The settings were set as
environment variables
and were visible for the app. - The newer version was NOT using
environment variables
, but was setting all custom properties asSystem Properties
. Tomcat received them as-DJDBC_CONNECTION_STRING=something
.
This changes the way on how to retrieve the properties from the server/Tomcat.
The solution
The solution - at least for this Spring Boot
Micro-service - was to add spring.datasource.url
directly into the Environment Properties
on the configuration page in AWS Elastic Beanstalk
. The title of the settings is misleading at least and judging it by its name and by the many years of use you would not expect this behavior.
Addition
After realizing what was happening I searched the docs for some clues. Here is an excerpt:
You can use environment properties to pass secrets, endpoints, debug settings, and other information to your application. Environment properties help you run your application in multiple environments for different purposes, such as development, testing, staging, and production.
Environment Variables
In most cases, environment properties are passed to your application as environment variables, but the behavior is platform dependent. For example, the Java SE platform sets environment variables that you retrieve with System.getenv, while the Tomcat platform sets Java system properties that you retrieve with System.getProperty.