<p>I have written a simple spring boot application(version springboot 2.0) which uses mysql(version 5.7).</p>

<p><strong>application.properties</strong> snippet</p>

<pre><code>spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
spring.datasource.username = testuser
spring.datasource.password = testpassword
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
</code></pre>

<p>When I run it locally, it works fine.
If I want to run this spring boot application in docker then I can change</p>

<pre><code>spring.datasource.url = jdbc:mysql://mysql-container:3306/test?useSSL=false
</code></pre>

<p><em>mysql-container is run using mysql:5.7 image from dockerhub.</em></p>

<p>However I want to change value of host from some placeholder properties file. so that this looks something like:</p>

<pre><code>spring.datasource.url = jdbc:mysql://${MYSQL_HOST}:3306/test?useSSL=false
</code></pre>

<p>note: I am not sure about placeholder format. Is it ${MYSQL_HOST} or @MYSQL_HOST@ ?</p>

<p>you can name this placeholder file as <em>placeholder.properties</em> or <em>placeholder.conf</em> or <em>.env</em> or anything. The content of that file should be something like:</p>

<pre><code>MYSQL_HOST=localhost
</code></pre>

<p>or</p>

<pre><code>MYSQL_HOST=some ip address
</code></pre>

<p>I can create .env or .env.test or .env.prod and I can refer that env file based on where I want to run application.</p>

<hr>

<p>UPDATE -</p>

<p>I have two questions:</p>

<ol>
<li><p>Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?</p></li>
<li><p>how to invoke placeholder inside application.properties ?</p></li>
</ol>

<p>can someone suggest?</p>

Shivraj
<p>SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?</p>

<p>You'd specify the environment at runtime with <code>-Dspring.profiles.active=myenv</code>.</p>

<p>Look <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html" rel="nofollow noreferrer">here</a> and <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-profile-specific-properties" rel="nofollow noreferrer">here</a>.</p>

<p>PS:</p>

<p>To answer your specific question: the syntax is <code>${MYSQL_HOST}</code></p>
