No data passed from the profile





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Im trying to implement profiles in Spring and for reason I dont understand I cannot pass the URL from choosen profile to applicartion.
The application.yml:



    spring:
main:
banner-mode: 'OFF'
profiles:
active: demo_prod
(…)
spring:
profiles: demo_prod
(…)
mUrl: "http://localhost:8081/private/configuration"


The BasicConfiguration:



    import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties

public class BasicConfiguration {

@Value("${mURL}")
private static String mURL;

public static String getMURL() {
return mURL;
}


CentralService:



    @Service
public class CentralServiceImpl implements CentralServiceAdapter {

private final String URL = BasicConfiguration.getMURL(); //Here debbuging shows URL: null


@Override
public void sendMAttributes(MAttributesDTO mAttributesDTO) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(URL); //Here debbuging shows URL: null
(…)


This URL is not passed, Postman shows error and breakpoint/debugging shows „URL null”. What I,m doing wrong? It seems that profile „demo_prod” is not choosen or the respecitve URL is not passed to application. I have no idea how to proceed further.










share|improve this question





























    0















    Im trying to implement profiles in Spring and for reason I dont understand I cannot pass the URL from choosen profile to applicartion.
    The application.yml:



        spring:
    main:
    banner-mode: 'OFF'
    profiles:
    active: demo_prod
    (…)
    spring:
    profiles: demo_prod
    (…)
    mUrl: "http://localhost:8081/private/configuration"


    The BasicConfiguration:



        import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.beans.factory.annotation.Value;

    @Configuration
    @EnableConfigurationProperties
    @ConfigurationProperties

    public class BasicConfiguration {

    @Value("${mURL}")
    private static String mURL;

    public static String getMURL() {
    return mURL;
    }


    CentralService:



        @Service
    public class CentralServiceImpl implements CentralServiceAdapter {

    private final String URL = BasicConfiguration.getMURL(); //Here debbuging shows URL: null


    @Override
    public void sendMAttributes(MAttributesDTO mAttributesDTO) throws IOException {
    CloseableHttpClient client = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(URL); //Here debbuging shows URL: null
    (…)


    This URL is not passed, Postman shows error and breakpoint/debugging shows „URL null”. What I,m doing wrong? It seems that profile „demo_prod” is not choosen or the respecitve URL is not passed to application. I have no idea how to proceed further.










    share|improve this question

























      0












      0








      0








      Im trying to implement profiles in Spring and for reason I dont understand I cannot pass the URL from choosen profile to applicartion.
      The application.yml:



          spring:
      main:
      banner-mode: 'OFF'
      profiles:
      active: demo_prod
      (…)
      spring:
      profiles: demo_prod
      (…)
      mUrl: "http://localhost:8081/private/configuration"


      The BasicConfiguration:



          import org.springframework.boot.context.properties.ConfigurationProperties;
      import org.springframework.boot.context.properties.EnableConfigurationProperties;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.beans.factory.annotation.Value;

      @Configuration
      @EnableConfigurationProperties
      @ConfigurationProperties

      public class BasicConfiguration {

      @Value("${mURL}")
      private static String mURL;

      public static String getMURL() {
      return mURL;
      }


      CentralService:



          @Service
      public class CentralServiceImpl implements CentralServiceAdapter {

      private final String URL = BasicConfiguration.getMURL(); //Here debbuging shows URL: null


      @Override
      public void sendMAttributes(MAttributesDTO mAttributesDTO) throws IOException {
      CloseableHttpClient client = HttpClients.createDefault();
      HttpPost httpPost = new HttpPost(URL); //Here debbuging shows URL: null
      (…)


      This URL is not passed, Postman shows error and breakpoint/debugging shows „URL null”. What I,m doing wrong? It seems that profile „demo_prod” is not choosen or the respecitve URL is not passed to application. I have no idea how to proceed further.










      share|improve this question














      Im trying to implement profiles in Spring and for reason I dont understand I cannot pass the URL from choosen profile to applicartion.
      The application.yml:



          spring:
      main:
      banner-mode: 'OFF'
      profiles:
      active: demo_prod
      (…)
      spring:
      profiles: demo_prod
      (…)
      mUrl: "http://localhost:8081/private/configuration"


      The BasicConfiguration:



          import org.springframework.boot.context.properties.ConfigurationProperties;
      import org.springframework.boot.context.properties.EnableConfigurationProperties;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.beans.factory.annotation.Value;

      @Configuration
      @EnableConfigurationProperties
      @ConfigurationProperties

      public class BasicConfiguration {

      @Value("${mURL}")
      private static String mURL;

      public static String getMURL() {
      return mURL;
      }


      CentralService:



          @Service
      public class CentralServiceImpl implements CentralServiceAdapter {

      private final String URL = BasicConfiguration.getMURL(); //Here debbuging shows URL: null


      @Override
      public void sendMAttributes(MAttributesDTO mAttributesDTO) throws IOException {
      CloseableHttpClient client = HttpClients.createDefault();
      HttpPost httpPost = new HttpPost(URL); //Here debbuging shows URL: null
      (…)


      This URL is not passed, Postman shows error and breakpoint/debugging shows „URL null”. What I,m doing wrong? It seems that profile „demo_prod” is not choosen or the respecitve URL is not passed to application. I have no idea how to proceed further.







      spring spring-profiles






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 10:06









      GregorSindGregorSind

      135




      135
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Firstly, this has nothing to do with spring profiles. This is basic spring injection at play.



          The reason it is not working is because your variable is static.



          @Value("${mURL}")
          private static String mURL;


          static is evil in terms of Spring. Avoid static as far as possible. Spring doesn't inject values to static variables. If you still wish to do it, there is a workaroud. You can do it using setter method



          private static String mURL; 

          @Value("${mURL}")
          public void setMUrl(String url){
          mURL = url;
          }


          And lastly(Not related to this issue). When you are using



          @ConfigurationProperties


          avoid @Value, this defeats the pupose of using ConfigurationProperties






          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%2f54020077%2fno-data-passed-from-the-profile%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Firstly, this has nothing to do with spring profiles. This is basic spring injection at play.



            The reason it is not working is because your variable is static.



            @Value("${mURL}")
            private static String mURL;


            static is evil in terms of Spring. Avoid static as far as possible. Spring doesn't inject values to static variables. If you still wish to do it, there is a workaroud. You can do it using setter method



            private static String mURL; 

            @Value("${mURL}")
            public void setMUrl(String url){
            mURL = url;
            }


            And lastly(Not related to this issue). When you are using



            @ConfigurationProperties


            avoid @Value, this defeats the pupose of using ConfigurationProperties






            share|improve this answer




























              0














              Firstly, this has nothing to do with spring profiles. This is basic spring injection at play.



              The reason it is not working is because your variable is static.



              @Value("${mURL}")
              private static String mURL;


              static is evil in terms of Spring. Avoid static as far as possible. Spring doesn't inject values to static variables. If you still wish to do it, there is a workaroud. You can do it using setter method



              private static String mURL; 

              @Value("${mURL}")
              public void setMUrl(String url){
              mURL = url;
              }


              And lastly(Not related to this issue). When you are using



              @ConfigurationProperties


              avoid @Value, this defeats the pupose of using ConfigurationProperties






              share|improve this answer


























                0












                0








                0







                Firstly, this has nothing to do with spring profiles. This is basic spring injection at play.



                The reason it is not working is because your variable is static.



                @Value("${mURL}")
                private static String mURL;


                static is evil in terms of Spring. Avoid static as far as possible. Spring doesn't inject values to static variables. If you still wish to do it, there is a workaroud. You can do it using setter method



                private static String mURL; 

                @Value("${mURL}")
                public void setMUrl(String url){
                mURL = url;
                }


                And lastly(Not related to this issue). When you are using



                @ConfigurationProperties


                avoid @Value, this defeats the pupose of using ConfigurationProperties






                share|improve this answer













                Firstly, this has nothing to do with spring profiles. This is basic spring injection at play.



                The reason it is not working is because your variable is static.



                @Value("${mURL}")
                private static String mURL;


                static is evil in terms of Spring. Avoid static as far as possible. Spring doesn't inject values to static variables. If you still wish to do it, there is a workaroud. You can do it using setter method



                private static String mURL; 

                @Value("${mURL}")
                public void setMUrl(String url){
                mURL = url;
                }


                And lastly(Not related to this issue). When you are using



                @ConfigurationProperties


                avoid @Value, this defeats the pupose of using ConfigurationProperties







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 10:15









                pvpkiranpvpkiran

                12.4k42645




                12.4k42645
































                    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%2f54020077%2fno-data-passed-from-the-profile%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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith