You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Dan Tran <da...@gmail.com> on 2011/03/13 08:02:07 UTC

Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Hello,

My jar ( spring bundle ) has a default set of configurations via

  <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="location" value="classpath:com/.../resources.properties" />
  </bean>

This way I  can override the default properties using system
properties ( ie pass in -Dxuy=value to JVM )

Now I'd like to deploy my bundle  to Karaf, is there a way for me to
setup Karaf/osgi's configAdmin to to use a config file under karaf's
etc directory to override my default properties?

Big thanks ahead.

-Dan

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Dan Tran <da...@gmail.com>.
yes, I read that doc many times.  and dont see anything point to what
I need.  However, with Achim's help, I think i should refactor my
spring configuration.

-D

On Mon, Mar 14, 2011 at 1:47 PM, karafman <mv...@comcast.net> wrote:
>
> dantran wrote:
>>
>> Hello,
>>
>> My jar ( spring bundle ) has a default set of configurations via
>>
>>
>>
>>
>>
>>
>> This way I  can override the default properties using system
>> properties ( ie pass in -Dxuy=value to JVM )
>>
>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>> etc directory to override my default properties?
>>
>> Big thanks ahead.
>>
>> -Dan
>>
>
> Dan,
>
> I hate to be an RTFM kind of guy, but we actually did a write up on how to
> do this
> http://karaf.apache.org/manual/2.1.99-SNAPSHOT/users-guide/provisioning.html
> here .
>
> Scroll down to the section on "Configuration", and it should give you the
> information you're looking for.  Please let us know if there's anything else
> we can do for you.
>
>
> -----
> Karafman
> Slayer of the JEE
> Pounder of the Perl Programmer
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Override-Spring-s-PropertyPlaceholderConfigurer-with-a-karaf-s-etc-s-config-file-tp2671821p2677306.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by karafman <mv...@comcast.net>.
dantran wrote:
> 
> Hello,
> 
> My jar ( spring bundle ) has a default set of configurations via
> 
>   
>     
>     
>   
> 
> This way I  can override the default properties using system
> properties ( ie pass in -Dxuy=value to JVM )
> 
> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
> setup Karaf/osgi's configAdmin to to use a config file under karaf's
> etc directory to override my default properties?
> 
> Big thanks ahead.
> 
> -Dan
> 

Dan,

I hate to be an RTFM kind of guy, but we actually did a write up on how to
do this 
http://karaf.apache.org/manual/2.1.99-SNAPSHOT/users-guide/provisioning.html
here .

Scroll down to the section on "Configuration", and it should give you the
information you're looking for.  Please let us know if there's anything else
we can do for you.  


-----
Karafman
Slayer of the JEE
Pounder of the Perl Programmer

--
View this message in context: http://karaf.922171.n3.nabble.com/Override-Spring-s-PropertyPlaceholderConfigurer-with-a-karaf-s-etc-s-config-file-tp2671821p2677306.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Dan Tran <da...@gmail.com>.
Hi Achim,

Thanks for the extended offer.  I am marching my way to OSGI
ConfigAdmin, Next I will walk to JMX way, i am very sure will need
more advice

-Dan

On Sun, Mar 13, 2011 at 1:11 PM, Achim Nierbeck <bc...@googlemail.com> wrote:
> Hi Dan,
>
> no problem, if there is anything else we can help on come back :)
>
> Regards, Achim
>
>> Hi Achim,
>>
>> I think it is reasonable to refactor my spring configuration to
>> separate standalone spring app and osgi app, rather then mixing them
>> and hope for the best
>>
>> Thank you for all the great advice.
>>
>> -Dan
>>
>>
>>
>> On Sun, Mar 13, 2011 at 12:35 PM, Achim Nierbeck
>> <bc...@googlemail.com> wrote:
>>> Hi Dan,
>>>
>>> depends on how you setup your Spring and your application.
>>> I usually use maven as build system and therefore do differentiate
>>> between spring in test and on server.
>>> In you "test" environment you can keep your configuration.
>>>
>>> One other possibility is how you tell spring / spring-dm which config
>>> files to use.
>>>
>>> Per default spring-dm searches for a spring xml file in META-INF/spring
>>> but you can also
>>> tell spring to search in other directories or just to use certain xml
>>> files.
>>> For example you might set the following in the MANIFEST
>>>
>>> Spring-Context: config/account-data-context.xml, config/account-security-context.xml
>>>
>>>
>>> More details on how to configure spring and so forth can be found at [1]
>>>
>>> Another thing I usually do is to separate Spring bean wiring from it's
>>> configuration, this way you can
>>> use different configurations for different locations.
>>>
>>>
>>>
>>> [1] -
>>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:headers
>>>
>>>
>>>> Hi Achim
>>>>
>>>> what do you mean by "Now you just need to replace your property code
>>>> by the following."?
>>>>
>>>> does this mean i need to remove my spring
>>>>
>>>>  <bean id="propertyConfigurer"
>>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>>      <property name="systemPropertiesModeName"
>>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>>      <property name="location" value="classpath:com/.../resources.properties" />
>>>>   </bean>
>>>>
>>>> as well?
>>>>
>>>> I am hoping to leave my spring config untouched  until we fully
>>>> OSGIzing it, so that my current test still functional as standlone
>>>> spring test
>>>>
>>>> Thank you
>>>>
>>>> -Dan
>>>>
>>>>
>>>> On Sun, Mar 13, 2011 at 12:09 PM, Achim Nierbeck
>>>> <bc...@googlemail.com> wrote:
>>>>> Hi Dan,
>>>>>
>>>>> yes it is.
>>>>>
>>>>> first of all you need to make sure you got a cfg file in your etc folder
>>>>> with a name that matches a "PID" - PersistentID
>>>>> e.g. my.very.special.resources.cfg
>>>>> where my.very.special.resources is the pid.
>>>>> This way the FileInstaller takes this cfg file and tells the config
>>>>> admin service to provide a configuration for that pid.
>>>>>
>>>>> Now you just need to replace your property code by the following.
>>>>>
>>>>> <osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
>>>>>      <beans:prop key="host">localhost</beans:prop>
>>>>>      <beans:prop key="port">3306</beans:prop>
>>>>> </osgix:cm-properties>
>>>>>
>>>>>
>>>>>
>>>>> It can also be found at [1]
>>>>>
>>>>>
>>>>> Regards, Achim
>>>>>
>>>>>
>>>>> [1]  -
>>>>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm
>>>>>
>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> My jar ( spring bundle ) has a default set of configurations via
>>>>>>
>>>>>>   <bean id="propertyConfigurer"
>>>>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>>>>     <property name="systemPropertiesModeName"
>>>>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>>>>     <property name="location" value="classpath:com/.../resources.properties" />
>>>>>>   </bean>
>>>>>>
>>>>>> This way I  can override the default properties using system
>>>>>> properties ( ie pass in -Dxuy=value to JVM )
>>>>>>
>>>>>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>>>>>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>>>>>> etc directory to override my default properties?
>>>>>>
>>>>>> Big thanks ahead.
>>>>>>
>>>>>> -Dan
>>>
>
>

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Dan,

no problem, if there is anything else we can help on come back :)

Regards, Achim

> Hi Achim,
>
> I think it is reasonable to refactor my spring configuration to
> separate standalone spring app and osgi app, rather then mixing them
> and hope for the best
>
> Thank you for all the great advice.
>
> -Dan
>
>
>
> On Sun, Mar 13, 2011 at 12:35 PM, Achim Nierbeck
> <bc...@googlemail.com> wrote:
>> Hi Dan,
>>
>> depends on how you setup your Spring and your application.
>> I usually use maven as build system and therefore do differentiate
>> between spring in test and on server.
>> In you "test" environment you can keep your configuration.
>>
>> One other possibility is how you tell spring / spring-dm which config
>> files to use.
>>
>> Per default spring-dm searches for a spring xml file in META-INF/spring
>> but you can also
>> tell spring to search in other directories or just to use certain xml
>> files.
>> For example you might set the following in the MANIFEST
>>
>> Spring-Context: config/account-data-context.xml, config/account-security-context.xml
>>
>>
>> More details on how to configure spring and so forth can be found at [1]
>>
>> Another thing I usually do is to separate Spring bean wiring from it's
>> configuration, this way you can
>> use different configurations for different locations.
>>
>>
>>
>> [1] -
>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:headers
>>
>>
>>> Hi Achim
>>>
>>> what do you mean by "Now you just need to replace your property code
>>> by the following."?
>>>
>>> does this mean i need to remove my spring
>>>
>>>  <bean id="propertyConfigurer"
>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>      <property name="systemPropertiesModeName"
>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>      <property name="location" value="classpath:com/.../resources.properties" />
>>>   </bean>
>>>
>>> as well?
>>>
>>> I am hoping to leave my spring config untouched  until we fully
>>> OSGIzing it, so that my current test still functional as standlone
>>> spring test
>>>
>>> Thank you
>>>
>>> -Dan
>>>
>>>
>>> On Sun, Mar 13, 2011 at 12:09 PM, Achim Nierbeck
>>> <bc...@googlemail.com> wrote:
>>>> Hi Dan,
>>>>
>>>> yes it is.
>>>>
>>>> first of all you need to make sure you got a cfg file in your etc folder
>>>> with a name that matches a "PID" - PersistentID
>>>> e.g. my.very.special.resources.cfg
>>>> where my.very.special.resources is the pid.
>>>> This way the FileInstaller takes this cfg file and tells the config
>>>> admin service to provide a configuration for that pid.
>>>>
>>>> Now you just need to replace your property code by the following.
>>>>
>>>> <osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
>>>>      <beans:prop key="host">localhost</beans:prop>
>>>>      <beans:prop key="port">3306</beans:prop>
>>>> </osgix:cm-properties>
>>>>
>>>>
>>>>
>>>> It can also be found at [1]
>>>>
>>>>
>>>> Regards, Achim
>>>>
>>>>
>>>> [1]  -
>>>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> My jar ( spring bundle ) has a default set of configurations via
>>>>>
>>>>>   <bean id="propertyConfigurer"
>>>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>>>     <property name="systemPropertiesModeName"
>>>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>>>     <property name="location" value="classpath:com/.../resources.properties" />
>>>>>   </bean>
>>>>>
>>>>> This way I  can override the default properties using system
>>>>> properties ( ie pass in -Dxuy=value to JVM )
>>>>>
>>>>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>>>>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>>>>> etc directory to override my default properties?
>>>>>
>>>>> Big thanks ahead.
>>>>>
>>>>> -Dan
>>


Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Dan Tran <da...@gmail.com>.
Hi Achim,

I think it is reasonable to refactor my spring configuration to
separate standalone spring app and osgi app, rather then mixing them
and hope for the best

Thank you for all the great advice.

-Dan



On Sun, Mar 13, 2011 at 12:35 PM, Achim Nierbeck
<bc...@googlemail.com> wrote:
> Hi Dan,
>
> depends on how you setup your Spring and your application.
> I usually use maven as build system and therefore do differentiate
> between spring in test and on server.
> In you "test" environment you can keep your configuration.
>
> One other possibility is how you tell spring / spring-dm which config
> files to use.
>
> Per default spring-dm searches for a spring xml file in META-INF/spring
> but you can also
> tell spring to search in other directories or just to use certain xml
> files.
> For example you might set the following in the MANIFEST
>
> Spring-Context: config/account-data-context.xml, config/account-security-context.xml
>
>
> More details on how to configure spring and so forth can be found at [1]
>
> Another thing I usually do is to separate Spring bean wiring from it's
> configuration, this way you can
> use different configurations for different locations.
>
>
>
> [1] -
> http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:headers
>
>
>> Hi Achim
>>
>> what do you mean by "Now you just need to replace your property code
>> by the following."?
>>
>> does this mean i need to remove my spring
>>
>>  <bean id="propertyConfigurer"
>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>      <property name="systemPropertiesModeName"
>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>      <property name="location" value="classpath:com/.../resources.properties" />
>>   </bean>
>>
>> as well?
>>
>> I am hoping to leave my spring config untouched  until we fully
>> OSGIzing it, so that my current test still functional as standlone
>> spring test
>>
>> Thank you
>>
>> -Dan
>>
>>
>> On Sun, Mar 13, 2011 at 12:09 PM, Achim Nierbeck
>> <bc...@googlemail.com> wrote:
>>> Hi Dan,
>>>
>>> yes it is.
>>>
>>> first of all you need to make sure you got a cfg file in your etc folder
>>> with a name that matches a "PID" - PersistentID
>>> e.g. my.very.special.resources.cfg
>>> where my.very.special.resources is the pid.
>>> This way the FileInstaller takes this cfg file and tells the config
>>> admin service to provide a configuration for that pid.
>>>
>>> Now you just need to replace your property code by the following.
>>>
>>> <osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
>>>      <beans:prop key="host">localhost</beans:prop>
>>>      <beans:prop key="port">3306</beans:prop>
>>> </osgix:cm-properties>
>>>
>>>
>>>
>>> It can also be found at [1]
>>>
>>>
>>> Regards, Achim
>>>
>>>
>>> [1]  -
>>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm
>>>
>>>
>>>> Hello,
>>>>
>>>> My jar ( spring bundle ) has a default set of configurations via
>>>>
>>>>   <bean id="propertyConfigurer"
>>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>>     <property name="systemPropertiesModeName"
>>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>>     <property name="location" value="classpath:com/.../resources.properties" />
>>>>   </bean>
>>>>
>>>> This way I  can override the default properties using system
>>>> properties ( ie pass in -Dxuy=value to JVM )
>>>>
>>>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>>>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>>>> etc directory to override my default properties?
>>>>
>>>> Big thanks ahead.
>>>>
>>>> -Dan
>>>
>
>

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Dan,

depends on how you setup your Spring and your application.
I usually use maven as build system and therefore do differentiate
between spring in test and on server.
In you "test" environment you can keep your configuration.

One other possibility is how you tell spring / spring-dm which config
files to use.

Per default spring-dm searches for a spring xml file in META-INF/spring
but you can also
tell spring to search in other directories or just to use certain xml
files.
For example you might set the following in the MANIFEST

Spring-Context: config/account-data-context.xml, config/account-security-context.xml


More details on how to configure spring and so forth can be found at [1]

Another thing I usually do is to separate Spring bean wiring from it's
configuration, this way you can
use different configurations for different locations.



[1] -
http://static.springsource.org/osgi/docs/1.2.1/reference/html/app-deploy.html#app-deploy:headers


> Hi Achim
>
> what do you mean by "Now you just need to replace your property code
> by the following."?
>
> does this mean i need to remove my spring
>
>  <bean id="propertyConfigurer"
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>      <property name="systemPropertiesModeName"
> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>      <property name="location" value="classpath:com/.../resources.properties" />
>   </bean>
>
> as well?
>
> I am hoping to leave my spring config untouched  until we fully
> OSGIzing it, so that my current test still functional as standlone
> spring test
>
> Thank you
>
> -Dan
>
>
> On Sun, Mar 13, 2011 at 12:09 PM, Achim Nierbeck
> <bc...@googlemail.com> wrote:
>> Hi Dan,
>>
>> yes it is.
>>
>> first of all you need to make sure you got a cfg file in your etc folder
>> with a name that matches a "PID" - PersistentID
>> e.g. my.very.special.resources.cfg
>> where my.very.special.resources is the pid.
>> This way the FileInstaller takes this cfg file and tells the config
>> admin service to provide a configuration for that pid.
>>
>> Now you just need to replace your property code by the following.
>>
>> <osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
>>      <beans:prop key="host">localhost</beans:prop>
>>      <beans:prop key="port">3306</beans:prop>
>> </osgix:cm-properties>
>>
>>
>>
>> It can also be found at [1]
>>
>>
>> Regards, Achim
>>
>>
>> [1]  -
>> http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm
>>
>>
>>> Hello,
>>>
>>> My jar ( spring bundle ) has a default set of configurations via
>>>
>>>   <bean id="propertyConfigurer"
>>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>>     <property name="systemPropertiesModeName"
>>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>>     <property name="location" value="classpath:com/.../resources.properties" />
>>>   </bean>
>>>
>>> This way I  can override the default properties using system
>>> properties ( ie pass in -Dxuy=value to JVM )
>>>
>>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>>> etc directory to override my default properties?
>>>
>>> Big thanks ahead.
>>>
>>> -Dan
>>


Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Dan Tran <da...@gmail.com>.
Hi Achim

what do you mean by "Now you just need to replace your property code
by the following."?

does this mean i need to remove my spring

 <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
     <property name="location" value="classpath:com/.../resources.properties" />
  </bean>

as well?

I am hoping to leave my spring config untouched  until we fully
OSGIzing it, so that my current test still functional as standlone
spring test

Thank you

-Dan


On Sun, Mar 13, 2011 at 12:09 PM, Achim Nierbeck
<bc...@googlemail.com> wrote:
> Hi Dan,
>
> yes it is.
>
> first of all you need to make sure you got a cfg file in your etc folder
> with a name that matches a "PID" - PersistentID
> e.g. my.very.special.resources.cfg
> where my.very.special.resources is the pid.
> This way the FileInstaller takes this cfg file and tells the config
> admin service to provide a configuration for that pid.
>
> Now you just need to replace your property code by the following.
>
> <osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
>      <beans:prop key="host">localhost</beans:prop>
>      <beans:prop key="port">3306</beans:prop>
> </osgix:cm-properties>
>
>
>
> It can also be found at [1]
>
>
> Regards, Achim
>
>
> [1]  -
> http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm
>
>
>> Hello,
>>
>> My jar ( spring bundle ) has a default set of configurations via
>>
>>   <bean id="propertyConfigurer"
>> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>>     <property name="systemPropertiesModeName"
>> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>>     <property name="location" value="classpath:com/.../resources.properties" />
>>   </bean>
>>
>> This way I  can override the default properties using system
>> properties ( ie pass in -Dxuy=value to JVM )
>>
>> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
>> setup Karaf/osgi's configAdmin to to use a config file under karaf's
>> etc directory to override my default properties?
>>
>> Big thanks ahead.
>>
>> -Dan
>
>

Re: Override Spring's PropertyPlaceholderConfigurer with a karaf's etc's config file

Posted by Achim Nierbeck <bc...@googlemail.com>.
Hi Dan,

yes it is.

first of all you need to make sure you got a cfg file in your etc folder
with a name that matches a "PID" - PersistentID
e.g. my.very.special.resources.cfg
where my.very.special.resources is the pid.
This way the FileInstaller takes this cfg file and tells the config
admin service to provide a configuration for that pid.

Now you just need to replace your property code by the following.

<osgix:cm-properties id="cfg.with.defaults" persistent-id="my.very.special.resources">
      <beans:prop key="host">localhost</beans:prop>
      <beans:prop key="port">3306</beans:prop>
</osgix:cm-properties>



It can also be found at [1]


Regards, Achim


[1]  -
http://static.springsource.org/osgi/docs/1.2.1/reference/html/compendium.html#compendium:cm


> Hello,
>
> My jar ( spring bundle ) has a default set of configurations via
>
>   <bean id="propertyConfigurer"
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
>     <property name="systemPropertiesModeName"
> value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
>     <property name="location" value="classpath:com/.../resources.properties" />
>   </bean>
>
> This way I  can override the default properties using system
> properties ( ie pass in -Dxuy=value to JVM )
>
> Now I'd like to deploy my bundle  to Karaf, is there a way for me to
> setup Karaf/osgi's configAdmin to to use a config file under karaf's
> etc directory to override my default properties?
>
> Big thanks ahead.
>
> -Dan