spring boot usage of placeholder in application properties
I have written a simple spring boot application(version springboot 2.0) which uses mysql(version 5.7).
application.properties snippet
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
When I run it locally, it works fine.
If I want to run this spring boot application in docker then I can change
spring.datasource.url = jdbc:mysql://mysql-container:3306/test?useSSL=false
mysql-container is run using mysql:5.7 image from dockerhub.
However I want to change value of host from some placeholder properties file. so that this looks something like:
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
note: I am not sure about placeholder format. Is it $MYSQL_HOST or @MYSQL_HOST@ ?
you can name this placeholder file as placeholder.properties or placeholder.conf or .env or anything. The content of that file should be something like:
MYSQL_HOST=localhost
or
MYSQL_HOST=some ip address
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.
UPDATE -
I have two questions:
Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?
how to invoke placeholder inside application.properties ?
can someone suggest?
mysql docker spring-boot kubernetes
add a comment |
I have written a simple spring boot application(version springboot 2.0) which uses mysql(version 5.7).
application.properties snippet
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
When I run it locally, it works fine.
If I want to run this spring boot application in docker then I can change
spring.datasource.url = jdbc:mysql://mysql-container:3306/test?useSSL=false
mysql-container is run using mysql:5.7 image from dockerhub.
However I want to change value of host from some placeholder properties file. so that this looks something like:
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
note: I am not sure about placeholder format. Is it $MYSQL_HOST or @MYSQL_HOST@ ?
you can name this placeholder file as placeholder.properties or placeholder.conf or .env or anything. The content of that file should be something like:
MYSQL_HOST=localhost
or
MYSQL_HOST=some ip address
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.
UPDATE -
I have two questions:
Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?
how to invoke placeholder inside application.properties ?
can someone suggest?
mysql docker spring-boot kubernetes
1
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33
add a comment |
I have written a simple spring boot application(version springboot 2.0) which uses mysql(version 5.7).
application.properties snippet
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
When I run it locally, it works fine.
If I want to run this spring boot application in docker then I can change
spring.datasource.url = jdbc:mysql://mysql-container:3306/test?useSSL=false
mysql-container is run using mysql:5.7 image from dockerhub.
However I want to change value of host from some placeholder properties file. so that this looks something like:
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
note: I am not sure about placeholder format. Is it $MYSQL_HOST or @MYSQL_HOST@ ?
you can name this placeholder file as placeholder.properties or placeholder.conf or .env or anything. The content of that file should be something like:
MYSQL_HOST=localhost
or
MYSQL_HOST=some ip address
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.
UPDATE -
I have two questions:
Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?
how to invoke placeholder inside application.properties ?
can someone suggest?
mysql docker spring-boot kubernetes
I have written a simple spring boot application(version springboot 2.0) which uses mysql(version 5.7).
application.properties snippet
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
When I run it locally, it works fine.
If I want to run this spring boot application in docker then I can change
spring.datasource.url = jdbc:mysql://mysql-container:3306/test?useSSL=false
mysql-container is run using mysql:5.7 image from dockerhub.
However I want to change value of host from some placeholder properties file. so that this looks something like:
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
note: I am not sure about placeholder format. Is it $MYSQL_HOST or @MYSQL_HOST@ ?
you can name this placeholder file as placeholder.properties or placeholder.conf or .env or anything. The content of that file should be something like:
MYSQL_HOST=localhost
or
MYSQL_HOST=some ip address
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.
UPDATE -
I have two questions:
Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?
how to invoke placeholder inside application.properties ?
can someone suggest?
mysql docker spring-boot kubernetes
mysql docker spring-boot kubernetes
edited Nov 14 '18 at 17:19
paulsm4
78.5k9100126
78.5k9100126
asked Nov 13 '18 at 4:23
Shivraj JadhavShivraj Jadhav
98211
98211
1
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33
add a comment |
1
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33
1
1
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33
add a comment |
3 Answers
3
active
oldest
votes
SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?
You'd specify the environment at runtime with -Dspring.profiles.active=myenv.
Look here and here.
PS:
To answer your specific question: the syntax is $MYSQL_HOST
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
add a comment |
Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.
What I was trying to achieve:
- Deploy springboot application in docker and then to kubernetes.
- I was using minikube for local testing and wanted to pass minikube ip to datasource url.
How I fixed it:
I created configmap for mysql_user, mysql_password, mysql_host with respective values.
kubectl create configmap mysql-config
--from-literal=mysql_user=testuser
--from-literal=mysql_password=testuserpass
--from-literal=mysql_user=$(minikube ip)
and used these inside application.properties something like below
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
spring.datasource.username = $MYSQL_USER
spring.datasource.password = $MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and then used configmap values in deployment.yaml for kubernetes.
Then did start service for deployment.
add a comment |
If you project is Maven you can use maven filter:
<build>
<filters>
<filter>src/main/filters/myfilter.properties</filter>
</filters>
</build>
This generates the /target/classes/application.properties it has been filtered to contain the property values (with replaced placeholders)
http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273773%2fspring-boot-usage-of-placeholder-in-application-properties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?
You'd specify the environment at runtime with -Dspring.profiles.active=myenv.
Look here and here.
PS:
To answer your specific question: the syntax is $MYSQL_HOST
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
add a comment |
SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?
You'd specify the environment at runtime with -Dspring.profiles.active=myenv.
Look here and here.
PS:
To answer your specific question: the syntax is $MYSQL_HOST
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
add a comment |
SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?
You'd specify the environment at runtime with -Dspring.profiles.active=myenv.
Look here and here.
PS:
To answer your specific question: the syntax is $MYSQL_HOST
SUGGESTION: If you have a relatively small #/properties, why not just have a different application.properties file for each different environment?
You'd specify the environment at runtime with -Dspring.profiles.active=myenv.
Look here and here.
PS:
To answer your specific question: the syntax is $MYSQL_HOST
edited Nov 13 '18 at 5:07
answered Nov 13 '18 at 4:31
paulsm4paulsm4
78.5k9100126
78.5k9100126
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
add a comment |
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
I don't have small # properties, its just a snippet from actual properties file. So using profile is not an option.
– Shivraj Jadhav
Nov 13 '18 at 13:57
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
$MYSQL_HOST didn't work. I have updated description with 2 questions. See if you can suggest something.
– Shivraj Jadhav
Nov 13 '18 at 14:03
1
1
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
I apologize if I didn't make myself clear. 1) you have LOTS of options (cited above) including 24. Externalized Configuration and Properties with Spring and Spring Boot. Please read these links; please post back with specific questions. 2) I'd STRONGLY suggest using application.properties (for your common properties) AND profile-specific.properties. Both links discuss how. 3) $MYSQL_HOST should work, if the variable is defined correctly.
– paulsm4
Nov 13 '18 at 23:19
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
Thanks for suggestions. I had already gone thru these before posting the issue. I was trying to check if there is any simpler solution to this. Thanks anyways.
– Shivraj Jadhav
Nov 14 '18 at 15:32
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
My suggestion IS "simple" ... at the Spring Boot level. But the thing you failed to make clear in your question was that you wanted to configure the "profile" at the Kubernetes (Docker orchestration) level. "*.properties/profiles" is the best way to go for SpringBoot; "configmap" is a better way to go for Kubernetes; I'm glad you found a solution, and thank you for sharing it.
– paulsm4
Nov 14 '18 at 17:21
add a comment |
Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.
What I was trying to achieve:
- Deploy springboot application in docker and then to kubernetes.
- I was using minikube for local testing and wanted to pass minikube ip to datasource url.
How I fixed it:
I created configmap for mysql_user, mysql_password, mysql_host with respective values.
kubectl create configmap mysql-config
--from-literal=mysql_user=testuser
--from-literal=mysql_password=testuserpass
--from-literal=mysql_user=$(minikube ip)
and used these inside application.properties something like below
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
spring.datasource.username = $MYSQL_USER
spring.datasource.password = $MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and then used configmap values in deployment.yaml for kubernetes.
Then did start service for deployment.
add a comment |
Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.
What I was trying to achieve:
- Deploy springboot application in docker and then to kubernetes.
- I was using minikube for local testing and wanted to pass minikube ip to datasource url.
How I fixed it:
I created configmap for mysql_user, mysql_password, mysql_host with respective values.
kubectl create configmap mysql-config
--from-literal=mysql_user=testuser
--from-literal=mysql_password=testuserpass
--from-literal=mysql_user=$(minikube ip)
and used these inside application.properties something like below
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
spring.datasource.username = $MYSQL_USER
spring.datasource.password = $MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and then used configmap values in deployment.yaml for kubernetes.
Then did start service for deployment.
add a comment |
Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.
What I was trying to achieve:
- Deploy springboot application in docker and then to kubernetes.
- I was using minikube for local testing and wanted to pass minikube ip to datasource url.
How I fixed it:
I created configmap for mysql_user, mysql_password, mysql_host with respective values.
kubectl create configmap mysql-config
--from-literal=mysql_user=testuser
--from-literal=mysql_password=testuserpass
--from-literal=mysql_user=$(minikube ip)
and used these inside application.properties something like below
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
spring.datasource.username = $MYSQL_USER
spring.datasource.password = $MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and then used configmap values in deployment.yaml for kubernetes.
Then did start service for deployment.
Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.
What I was trying to achieve:
- Deploy springboot application in docker and then to kubernetes.
- I was using minikube for local testing and wanted to pass minikube ip to datasource url.
How I fixed it:
I created configmap for mysql_user, mysql_password, mysql_host with respective values.
kubectl create configmap mysql-config
--from-literal=mysql_user=testuser
--from-literal=mysql_password=testuserpass
--from-literal=mysql_user=$(minikube ip)
and used these inside application.properties something like below
spring.datasource.url = jdbc:mysql://$MYSQL_HOST:3306/test?useSSL=false
spring.datasource.username = $MYSQL_USER
spring.datasource.password = $MYSQL_PASSWORD
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
and then used configmap values in deployment.yaml for kubernetes.
Then did start service for deployment.
answered Nov 14 '18 at 15:30
Shivraj JadhavShivraj Jadhav
98211
98211
add a comment |
add a comment |
If you project is Maven you can use maven filter:
<build>
<filters>
<filter>src/main/filters/myfilter.properties</filter>
</filters>
</build>
This generates the /target/classes/application.properties it has been filtered to contain the property values (with replaced placeholders)
http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1
add a comment |
If you project is Maven you can use maven filter:
<build>
<filters>
<filter>src/main/filters/myfilter.properties</filter>
</filters>
</build>
This generates the /target/classes/application.properties it has been filtered to contain the property values (with replaced placeholders)
http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1
add a comment |
If you project is Maven you can use maven filter:
<build>
<filters>
<filter>src/main/filters/myfilter.properties</filter>
</filters>
</build>
This generates the /target/classes/application.properties it has been filtered to contain the property values (with replaced placeholders)
http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1
If you project is Maven you can use maven filter:
<build>
<filters>
<filter>src/main/filters/myfilter.properties</filter>
</filters>
</build>
This generates the /target/classes/application.properties it has been filtered to contain the property values (with replaced placeholders)
http://www.avajava.com/tutorials/lessons/how-do-i-filter-resources-based-on-values-from-a-properties-file.html?page=1
answered Jan 18 at 20:23
sytolksytolk
2,87221225
2,87221225
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273773%2fspring-boot-usage-of-placeholder-in-application-properties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I used place Holder in application.properties like $environment_prefix you can try this it will work.
– Raheela Aslam
Nov 13 '18 at 4:46
I tried $MYSQL_HOST, but that didn't work. Where exactly I should keep placeholder.properties file? check updated description.
– Shivraj Jadhav
Nov 13 '18 at 13:59
Please see answer posted. Your suggestion definitely helped.
– Shivraj Jadhav
Nov 14 '18 at 15:33