How do I read application properties in Micronaut?












0














I integrated AWS SES API to my Micronaut Groovy application using guide send mail in micronaut and I am able send mails if I directly assign values to properties.



I want to make it config driven hence have been trying to find ways to achieve that.



I tried @Value annotation as mentioned in guide but was not able to make it work.



@Value("aws.secretkeyid")
String keyId


Further digging into documentation revealed that Micronaut has its own annotation for injecting properties in variables.



@Property(name="aws.secretkeyid")
String keyId


But nothing seems to work, my variables are still null.



What could be possibly wrong here ?



For reference, following is in my application.yml file



aws:
keyid: "2weadasdwda"
secretkeyid: "abcdesdasdsddddd"
region: "us-east-1"









share|improve this question



























    0














    I integrated AWS SES API to my Micronaut Groovy application using guide send mail in micronaut and I am able send mails if I directly assign values to properties.



    I want to make it config driven hence have been trying to find ways to achieve that.



    I tried @Value annotation as mentioned in guide but was not able to make it work.



    @Value("aws.secretkeyid")
    String keyId


    Further digging into documentation revealed that Micronaut has its own annotation for injecting properties in variables.



    @Property(name="aws.secretkeyid")
    String keyId


    But nothing seems to work, my variables are still null.



    What could be possibly wrong here ?



    For reference, following is in my application.yml file



    aws:
    keyid: "2weadasdwda"
    secretkeyid: "abcdesdasdsddddd"
    region: "us-east-1"









    share|improve this question

























      0












      0








      0







      I integrated AWS SES API to my Micronaut Groovy application using guide send mail in micronaut and I am able send mails if I directly assign values to properties.



      I want to make it config driven hence have been trying to find ways to achieve that.



      I tried @Value annotation as mentioned in guide but was not able to make it work.



      @Value("aws.secretkeyid")
      String keyId


      Further digging into documentation revealed that Micronaut has its own annotation for injecting properties in variables.



      @Property(name="aws.secretkeyid")
      String keyId


      But nothing seems to work, my variables are still null.



      What could be possibly wrong here ?



      For reference, following is in my application.yml file



      aws:
      keyid: "2weadasdwda"
      secretkeyid: "abcdesdasdsddddd"
      region: "us-east-1"









      share|improve this question













      I integrated AWS SES API to my Micronaut Groovy application using guide send mail in micronaut and I am able send mails if I directly assign values to properties.



      I want to make it config driven hence have been trying to find ways to achieve that.



      I tried @Value annotation as mentioned in guide but was not able to make it work.



      @Value("aws.secretkeyid")
      String keyId


      Further digging into documentation revealed that Micronaut has its own annotation for injecting properties in variables.



      @Property(name="aws.secretkeyid")
      String keyId


      But nothing seems to work, my variables are still null.



      What could be possibly wrong here ?



      For reference, following is in my application.yml file



      aws:
      keyid: "2weadasdwda"
      secretkeyid: "abcdesdasdsddddd"
      region: "us-east-1"






      micronaut






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 17:55









      Aditya Thakur

      162112




      162112
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.



          The correct syntax is:



          @Value('${aws.secretkeyid}')
          String keyId


          Notice that you must use single quotes to avoid Groovy to attempt interpolation






          share|improve this answer























          • The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
            – Aditya Thakur
            Nov 23 at 11:05






          • 1




            The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
            – Álvaro Sánchez-Mariscal
            Nov 23 at 11:10






          • 1




            Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
            – Aditya Thakur
            Nov 23 at 18:06










          • I was going to answer it myself but your answer is correct as per the question. :)
            – Aditya Thakur
            Nov 23 at 18:07



















          0














          If anyone else stumbles upon this problem, you also have alternative to use @Property annotation in Micronaut ( starting from version 1.0.1 )



          Syntax is as follows



          @Property(name = "your.application.property")
          String propertyName


          PS : This is what was mentioned in Micronaut Documentation but was not working in my case as I was on Micronaut Version 1.0.0






          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%2f53436144%2fhow-do-i-read-application-properties-in-micronaut%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.



            The correct syntax is:



            @Value('${aws.secretkeyid}')
            String keyId


            Notice that you must use single quotes to avoid Groovy to attempt interpolation






            share|improve this answer























            • The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
              – Aditya Thakur
              Nov 23 at 11:05






            • 1




              The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
              – Álvaro Sánchez-Mariscal
              Nov 23 at 11:10






            • 1




              Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
              – Aditya Thakur
              Nov 23 at 18:06










            • I was going to answer it myself but your answer is correct as per the question. :)
              – Aditya Thakur
              Nov 23 at 18:07
















            2














            You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.



            The correct syntax is:



            @Value('${aws.secretkeyid}')
            String keyId


            Notice that you must use single quotes to avoid Groovy to attempt interpolation






            share|improve this answer























            • The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
              – Aditya Thakur
              Nov 23 at 11:05






            • 1




              The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
              – Álvaro Sánchez-Mariscal
              Nov 23 at 11:10






            • 1




              Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
              – Aditya Thakur
              Nov 23 at 18:06










            • I was going to answer it myself but your answer is correct as per the question. :)
              – Aditya Thakur
              Nov 23 at 18:07














            2












            2








            2






            You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.



            The correct syntax is:



            @Value('${aws.secretkeyid}')
            String keyId


            Notice that you must use single quotes to avoid Groovy to attempt interpolation






            share|improve this answer














            You are using it incorrectly, you are injecting the literal value aws.secretkeyid, not the value of a variable.



            The correct syntax is:



            @Value('${aws.secretkeyid}')
            String keyId


            Notice that you must use single quotes to avoid Groovy to attempt interpolation







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 28 at 6:20









            saw303

            3,42712955




            3,42712955










            answered Nov 23 at 10:54









            Álvaro Sánchez-Mariscal

            396210




            396210












            • The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
              – Aditya Thakur
              Nov 23 at 11:05






            • 1




              The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
              – Álvaro Sánchez-Mariscal
              Nov 23 at 11:10






            • 1




              Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
              – Aditya Thakur
              Nov 23 at 18:06










            • I was going to answer it myself but your answer is correct as per the question. :)
              – Aditya Thakur
              Nov 23 at 18:07


















            • The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
              – Aditya Thakur
              Nov 23 at 11:05






            • 1




              The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
              – Álvaro Sánchez-Mariscal
              Nov 23 at 11:10






            • 1




              Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
              – Aditya Thakur
              Nov 23 at 18:06










            • I was going to answer it myself but your answer is correct as per the question. :)
              – Aditya Thakur
              Nov 23 at 18:07
















            The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
            – Aditya Thakur
            Nov 23 at 11:05




            The syntax you mentioned is for Java, not for Groovy. I tried it first thing as it was in [send mail in micronaut] documentation, but code does not even compile if you use above syntax.
            – Aditya Thakur
            Nov 23 at 11:05




            1




            1




            The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
            – Álvaro Sánchez-Mariscal
            Nov 23 at 11:10




            The syntax I posted is for Groovy and does compile indeed. Notice that you must use single quotes to avoid Groovy to attempt interpolation.
            – Álvaro Sánchez-Mariscal
            Nov 23 at 11:10




            1




            1




            Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
            – Aditya Thakur
            Nov 23 at 18:06




            Indeed you are right, I made the mistake of using double quotes instead of single quotes. Although due to this silly mistake at my end, I ended up upgrading Micronaut version to 1.0.1 and used @Property(name = "aws.secretkeyid") :D
            – Aditya Thakur
            Nov 23 at 18:06












            I was going to answer it myself but your answer is correct as per the question. :)
            – Aditya Thakur
            Nov 23 at 18:07




            I was going to answer it myself but your answer is correct as per the question. :)
            – Aditya Thakur
            Nov 23 at 18:07













            0














            If anyone else stumbles upon this problem, you also have alternative to use @Property annotation in Micronaut ( starting from version 1.0.1 )



            Syntax is as follows



            @Property(name = "your.application.property")
            String propertyName


            PS : This is what was mentioned in Micronaut Documentation but was not working in my case as I was on Micronaut Version 1.0.0






            share|improve this answer


























              0














              If anyone else stumbles upon this problem, you also have alternative to use @Property annotation in Micronaut ( starting from version 1.0.1 )



              Syntax is as follows



              @Property(name = "your.application.property")
              String propertyName


              PS : This is what was mentioned in Micronaut Documentation but was not working in my case as I was on Micronaut Version 1.0.0






              share|improve this answer
























                0












                0








                0






                If anyone else stumbles upon this problem, you also have alternative to use @Property annotation in Micronaut ( starting from version 1.0.1 )



                Syntax is as follows



                @Property(name = "your.application.property")
                String propertyName


                PS : This is what was mentioned in Micronaut Documentation but was not working in my case as I was on Micronaut Version 1.0.0






                share|improve this answer












                If anyone else stumbles upon this problem, you also have alternative to use @Property annotation in Micronaut ( starting from version 1.0.1 )



                Syntax is as follows



                @Property(name = "your.application.property")
                String propertyName


                PS : This is what was mentioned in Micronaut Documentation but was not working in my case as I was on Micronaut Version 1.0.0







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 18:17









                Aditya Thakur

                162112




                162112






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53436144%2fhow-do-i-read-application-properties-in-micronaut%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

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    Alexandru Averescu

                    Trompette piccolo