Hi Jean-Philippe,
If I get you right you have too classes class Foo with a method public Bar
getBar() and your test class with a constructor that expects a Bar parameter.
You could do something like:
<bean id=”foo” class=”test.Foo” />
<bean id=”bar” factory-ref=”foo” factory-method=”getBar” />
<bean id=”sample” class=”test.TestClass”>
<argument ref=”bar” />
</bean>
Best regards
Stephan
From: CLEMENT Jean-Philippe [mailto:[email protected]]
Sent: Mittwoch, 4. September 2013 09:35
To: [email protected]
Subject: RE: Blueprint string substitution / placeholder
Stephan,
I just want to replace $(to.replace) by another value which comes from one of
my services/beans rather than directly from a file just as property-placeholder
does.
Digging into subject, it seems that Felix implementation of
property-placeholder delegates to all registered services which exposes the
PersistanceManager interface. I will give it a try.
Best regards,
Jean-Philippe
[@@ OPEN @@]
De : Siano, Stephan [mailto:[email protected]]
Envoyé : mercredi 4 septembre 2013 07:23
À : [email protected]<mailto:[email protected]>
Objet : RE: Blueprint string substitution / placeholder
Hi Jean-Philippe,
I actually don’t understand what you really mean by “correct value taken from a
java service and not directly from a file”.
Do you mean an OSGi service that can provide the required information? Or do
you mean a standard OSGi service like the config admin service? Or do you want
to get the information from a properties file without reading it in code?
If the value is provided by a method of an OSGi service you have actually two
options:
Reference the service, instantiate another bean for your parameter (e.g. one of
type String) using the method as factory method and the referenced service as a
factory. This has the disadvantage that the substitution is static (so even if
the value changes in the service it will not in your TestClass instance).
Alternatively you could change the test class to use the referenced service
directly. In that case the implementation could query the value at each usage
und would get the changes from the service.
If you read properties files or the config admin service there are properties
placeholders for that. With the config admin properties there is also some
dynamics possible but I haven’t really tried that out.
Best regards
Stephan
From: CLEMENT Jean-Philippe
[mailto:[email protected]]<mailto:[mailto:[email protected]]>
Sent: Dienstag, 3. September 2013 17:07
To: [email protected]<mailto:[email protected]>
Subject: Blueprint string substitution / placeholder
Hi,
I would like to replace Blueprint string values, for instance in:
<bean id=”sample” class=”test.TestClass”>
<argument value=”$(to.replace)” />
</bean>
Where $(to.replace) would be substituted by the correct value taken from a java
service and not directly from a file.
What would be the simplest way to do so? Is there a way to map a placeholder to
a bean?
Best regards,
Jean-Philippe
[@@ OPEN @@]