You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by glopez <lo...@gmail.com> on 2018/07/16 13:46:30 UTC
Setting environment variable as bean property
Hi,
I'm trying to work with environment variables (export foobar="linuxvar"),
this is what I have in my blueprint:
<cm:property-placeholder persistent-id="ReadEnvVar"
placeholder-prefix="#GW(" placeholder-suffix=")">
<cm:default-properties>
<cm:property name="message" value="${sysenv.foobar}" />
</cm:default-properties>
</cm:property-placeholder>
When I try to access the "message" value inside the camel context I have no
problem:
<camelContext id="blueprintContext" trace="false"
xmlns="http://camel.apache.org/schema/blueprint">
<route id="timerToLog">
<from uri="timer:foo?period=5000"/>
<log message="1. {{message}}"/>
<to uri="mock:result"/>
</route>
</camelContext>
I can see the "linuxvar"
My problem is when I try to set a bean property using the message value:
<bean id="myBean" class="beans.HelloBean">
<property name="say" value="#GW(message)"/>
</bean>
When I print the value of "say" I have "${sysenv.foobar}" instead of
"linuxvar".
Any clue of what I'm doing wrong?
Thanks
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: Setting environment variable as bean property
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Great it helped ;)
Regards
JB
On 17/07/2018 13:50, glopez wrote:
> Hi,
>
> I managed to do it with your help:
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>
> xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0">
>
> <ext:property-placeholder/>
>
> <bean ...>
> <property name="foo" value="${env:foo}"/>
> </beam>
>
> </blueprint>
>
> Thank you
>
>
>
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com
Re: Setting environment variable as bean property
Posted by glopez <lo...@gmail.com>.
Hi,
I managed to do it with your help:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0">
<ext:property-placeholder/>
<bean ...>
<property name="foo" value="${env:foo}"/>
</beam>
</blueprint>
Thank you
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: Setting environment variable as bean property
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,
to do this, you have to use the blueprint ext. For instance:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.2.0">
<ext:property-placeholder/>
<bean ...>
<property name="foo" value="${foo}"/>
</beam>
</blueprint>
where foo is a system property defined with JVM arg like -Dfoo=bar
Regards
JB
On 16/07/2018 15:46, glopez wrote:
> Hi,
>
> I'm trying to work with environment variables (export foobar="linuxvar"),
> this is what I have in my blueprint:
>
> <cm:property-placeholder persistent-id="ReadEnvVar"
> placeholder-prefix="#GW(" placeholder-suffix=")">
> <cm:default-properties>
> <cm:property name="message" value="${sysenv.foobar}" />
> </cm:default-properties>
> </cm:property-placeholder>
>
> When I try to access the "message" value inside the camel context I have no
> problem:
>
> <camelContext id="blueprintContext" trace="false"
> xmlns="http://camel.apache.org/schema/blueprint">
> <route id="timerToLog">
> <from uri="timer:foo?period=5000"/>
> <log message="1. {{message}}"/>
> <to uri="mock:result"/>
> </route>
> </camelContext>
>
> I can see the "linuxvar"
>
> My problem is when I try to set a bean property using the message value:
>
> <bean id="myBean" class="beans.HelloBean">
> <property name="say" value="#GW(message)"/>
> </bean>
>
> When I print the value of "say" I have "${sysenv.foobar}" instead of
> "linuxvar".
>
> Any clue of what I'm doing wrong?
>
> Thanks
>
>
>
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com