1

I have declared one property in the application.properties file like below

hu.ednpoint=https://${serverhost.name}/subscription/event
de.ednpoint=https://${serverhost.name}/consume/event 

I am expecting the value of ${serverhost.name} will be overridden by api.xfjj.com:443 but it's giving the below results accessing values camel route

.log("{{hu.ednpoint}}")
.log("{{de.ednpoint}}")
.to("{{de.ednpoint}}")
.end() 

Expected results :

hu.ednpoint=https://api.xfjj.com:443/subscription/event
de.ednpoint=https://api.xfjj.com:443/consume/event

Actual Results :

hu.ednpoint=https:/subscription/event
de.ednpoint=https:/consume/event

I am not sure where it's going wrong. I am really grateful if anyone could help me to resolve this issue.This issue is occurring in camel2 but in camel3 works fine

Balanjaneyulu P
  • 151
  • 1
  • 1
  • 6
  • Is that the actual endresult or something you typed out yourself from memory? Because in that endresult the double slashes have disappeared, there is more missing than only the variable value. – Gimby Aug 26 '21 at 15:26
  • yes it's end results // double slashes also missing – Balanjaneyulu P Aug 26 '21 at 15:30
  • Well then the problem is not with the serverhost.name property. Is Maven involved in this project? If so, is it configured to do resource filtering by any chance? – Gimby Aug 26 '21 at 15:38
  • 1
    How are you checking the actual results? I mean how and where are you fetching those properties? – Jignesh M. Khatri Aug 26 '21 at 15:42
  • Just tried to verify this "problem" and tried to check the result (with SB 2, not 1, but maybe in this case this is irrelevant): If I package the application (with maven) and look for the "substituted" `application.properties` (in the packaged jar), the variable is not substituted and the value is equal to the source `application.properties`. But if I write some (rest)controller, load the value with `@Value("${de.endpoint}") String deEndpoint` and print it to the console, the variable is substituted. – hjoeren Aug 26 '21 at 16:16
  • @hjoeren I guess that is expected behaviour. If you are using maven variables `@..@` then only they will be substituted at the time of build. Otherwise Spring placeholders `${...}` are substituted at the runtime only. It is well documented here - https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/howto-properties-and-configuration.html#howto-discover-build-in-options-for-external-properties – Jignesh M. Khatri Aug 26 '21 at 16:28
  • @JigneshM.Khatri Not sure if the question is about maven variables, because in the question it's given `serverhost.name=api.xfjj.com:443`. So I think the question is like "how can I use property `X` in the property `Y`, both are defined in `application.properties`". – hjoeren Aug 26 '21 at 16:36
  • 1
    @hjoeren Yeah I know that, I was just giving the explanation of your comment (you said that property was not replaced in Jar). As you said that it is working runtime, so I agree with you. It will work runtime without any issues. But need to get it clarified from OP that how and where properties are being accessed. – Jignesh M. Khatri Aug 26 '21 at 16:41
  • I am accessing in one customized spring class like below ``` @Component class Customer{ @value("${de.endpoint}") String hostName; somemethd(){ System.out.println(hostName); } }``` – Balanjaneyulu P Aug 27 '21 at 02:19
  • Just tried to reproduce with Spring Boot 1.5.22.RELEASE, but I'm not able to do so (https://gitlab.com/hjoeren/variable-substitution-sb1): The variable is resolved substituted. Can you tell us which version you are using? – hjoeren Aug 31 '21 at 17:12
  • The question seems to have an issue itself. actually, When i am accessing with @Value it's working fine but when I am accessing the value in camel route it's not working, now I need to edit the question properly – Balanjaneyulu P Sep 08 '21 at 04:38

1 Answers1

1

Could you please try using yaml instead of properties file. Eg.

apiConfig:
    pf:
      host:
        name: api.xfjj.com:443
      uri:
        base:
          admin: https://${apiConfig.pf.host.name}/
        apis:
          orders:
            get:
              subscription: ${apiConfig.pf.uri.base.admin}/suscription/event/
              consume:${apiConfig.pf.uri.base.admin}/consume/event/

Sujay Mohan
  • 933
  • 7
  • 14