spring boot usage of placeholder in application properties










1















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:



  1. Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?


  2. how to invoke placeholder inside application.properties ?


can someone suggest?










share|improve this question



















  • 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















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:



  1. Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?


  2. how to invoke placeholder inside application.properties ?


can someone suggest?










share|improve this question



















  • 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








1








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:



  1. Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?


  2. how to invoke placeholder inside application.properties ?


can someone suggest?










share|improve this question
















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:



  1. Where should I keep placeholder.properties? Is it under /config/ or under some specific directory?


  2. how to invoke placeholder inside application.properties ?


can someone suggest?







mysql docker spring-boot kubernetes






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












3 Answers
3






active

oldest

votes


















1














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






share|improve this answer

























  • 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



















1














Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.



What I was trying to achieve:



  1. Deploy springboot application in docker and then to kubernetes.

  2. 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.






share|improve this answer






























    0














    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






    share|improve this answer






















      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
      );



      );













      draft saved

      draft discarded


















      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









      1














      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






      share|improve this answer

























      • 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
















      1














      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






      share|improve this answer

























      • 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














      1












      1








      1







      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






      share|improve this answer















      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







      share|improve this answer














      share|improve this answer



      share|improve this answer








      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


















      • 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














      1














      Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.



      What I was trying to achieve:



      1. Deploy springboot application in docker and then to kubernetes.

      2. 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.






      share|improve this answer



























        1














        Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.



        What I was trying to achieve:



        1. Deploy springboot application in docker and then to kubernetes.

        2. 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.






        share|improve this answer

























          1












          1








          1







          Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.



          What I was trying to achieve:



          1. Deploy springboot application in docker and then to kubernetes.

          2. 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.






          share|improve this answer













          Thanks to answers by @Raheela Aslam and @paulsm4 and some more research found the issue.



          What I was trying to achieve:



          1. Deploy springboot application in docker and then to kubernetes.

          2. 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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 15:30









          Shivraj JadhavShivraj Jadhav

          98211




          98211





















              0














              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






              share|improve this answer



























                0














                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






                share|improve this answer

























                  0












                  0








                  0







                  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






                  share|improve this answer













                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 18 at 20:23









                  sytolksytolk

                  2,87221225




                  2,87221225



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Kleinkühnau

                      Makov (Slowakei)

                      Deutsches Schauspielhaus