Platform.sh User Documentation

Customize Spring for Platform.sh

Try for 30 days
Flexible, version-controlled infrastructure provisioning and development-to-production workflows
Activate your trial

Now that your code contains all of the configuration to deploy on Platform.sh, it’s time to make your Spring site itself ready to run on a Platform.sh environment. There are a number of additional steps that are either required or recommended, depending on how well you want to optimize your site.

Install the Config Reader Anchor to this heading

You can get all information about a deployed environment, including how to connect to services, through environment variables. Your app can access these variables.

Below is an example of how to install the Config Reader for Java using Maven:

<dependency>
    <groupId>sh.platform</groupId>
    <artifactId>config</artifactId>
    <version>2.2.2</version>
</dependency>

and Gradle:

compile group: 'sh.platform', name: 'config', version: '2.2.2'

.environment Anchor to this heading

The .platform.app.yaml file in the previous step has been pulled directly from the Spring template. It is sufficient to deploy Spring on its own, but since Spring Config makes it possible to overwrite configurations without impacting the application itself, you might elect to rely more heavily on environment variables in its place.

Consider this simplified .platform.app.yaml file:

.platform.app.yaml
name: myapp
type: "java:11"
disk: 1024
hooks:
  build: mvn clean package
web:
  commands:
    start: java -jar $JAVA_OPTS target/file.jar --server.port=$PORT

On Platform.sh, we can set the environment variable JAVA_OPTS by committing a .environment file to the repository’s root. Platform.sh runs source .environment in the application root when a project starts, and when logging into the environment over SSH. That gives you a place to do extra environment variable setup prior to the application running, including modifying the system $PATH and other shell level customizations. It allows us to define JAVA_OPTS when running on Platform.sh, but otherwise not be used during local development testing.

# .environment
export JAVA_OPTS="-Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError"

Is this page helpful?