Property files with Spring Configuration (PropertyPlaceholderConfigurer)

View: New views
7 Messages — Rating Filter:   Alert me  

Property files with Spring Configuration (PropertyPlaceholderConfigurer)

by David Latorre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Niklas,

I'd like  the configurable part of my ftpserver (e.g., IP -since we have
several hosts) in a property file using PropertyPlaceholderCinfigurer
Its use is explained here:
http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-placeholderconfigurer
This way IT people can modify a properties file which is simpler for them
than editing the full spring xml.

The thing is I'm not familiar with Spring so - can we use this approach
using the customized XML config ? For example, I've tried to define "port"
as ${port} but it is not working; furthermore I've tried to define one of
the "value" of one of the properties of a beans:bean element (the datasource
configuration) and it is still not working so I wonder if i made a mistake
somewhere.



So, can you give me a hand with this ? my file starts with:

* I've use classpath:com/.../  to check if it was a problem with
file:fullpath/minaftp.properties

<beans:beans xmlns="http://mina.apache.org/ftpserver/spring/v1"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
           http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://mina.apache.org/ftpserver/spring/v1
http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
           ">

       <beans:bean id="properties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
>
        <beans:property name="locations">

<beans:value>classpath:com/mycompany/ftpserver/minaftp.properties</beans:value>
        </beans:property>
    </beans:bean>


    <server id="server">

My datasource config is :
               <data-source>
                        <beans:bean
class="org.springframework.jndi.JndiObjectFactoryBean">
                                <beans:property
name="jndiName"><beans:value>${config.name}</beans:value></beans:property>
                        </beans:bean>
                </data-source>

I'm stuck with a NameNotFoundException ${config.name} not found.


If anyone could point me on the right direction I'd most grateful.

Cheers,
  David Latorre

Re: Property files with Spring Configuration (PropertyPlaceholderConfigurer)

by David Latorre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BTW, since my knowledge of Spring is null, I think a more complete example
of xml configuration (e.g., defining a custom UserManager) could be included
along the existing xmls.

If there's a way to use the PropertyPlaceholder that you sent me an example
would be great for me too!





2008/9/5 David Latorre <dvlato@...>

> Hello Niklas,
>
> I'd like  the configurable part of my ftpserver (e.g., IP -since we have
> several hosts) in a property file using PropertyPlaceholderCinfigurer
> Its use is explained here:
> http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-placeholderconfigurer
> This way IT people can modify a properties file which is simpler for them
> than editing the full spring xml.
>
> The thing is I'm not familiar with Spring so - can we use this approach
> using the customized XML config ? For example, I've tried to define "port"
> as ${port} but it is not working; furthermore I've tried to define one of
> the "value" of one of the properties of a beans:bean element (the datasource
> configuration) and it is still not working so I wonder if i made a mistake
> somewhere.
>
>
>
> So, can you give me a hand with this ? my file starts with:
>
> * I've use classpath:com/.../  to check if it was a problem with
> file:fullpath/minaftp.properties
>
> <beans:beans xmlns="http://mina.apache.org/ftpserver/spring/v1"
>         xmlns:beans="http://www.springframework.org/schema/beans"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="
>            http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>            http://mina.apache.org/ftpserver/spring/v1
> http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
>            ">
>
>        <beans:bean id="properties"
> class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
> >
>         <beans:property name="locations">
>
> <beans:value>classpath:com/mycompany/ftpserver/minaftp.properties</beans:value>
>         </beans:property>
>     </beans:bean>
>
>
>     <server id="server">
>
> My datasource config is :
>                <data-source>
>                         <beans:bean
> class="org.springframework.jndi.JndiObjectFactoryBean">
>                                 <beans:property
> name="jndiName"><beans:value>${config.name}</beans:value></beans:property>
>                         </beans:bean>
>                 </data-source>
>
> I'm stuck with a NameNotFoundException ${config.name} not found.
>
>
> If anyone could point me on the right direction I'd most grateful.
>
> Cheers,
>   David Latorre
>

Re: Property files with Spring Configuration (PropertyPlaceholderConfigurer)

by Niklas Gustavsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Sep 5, 2008 at 12:53 PM, David Latorre <dvlato@...> wrote:
> I'd like  the configurable part of my ftpserver (e.g., IP -since we have
> several hosts) in a property file using PropertyPlaceholderCinfigurer
> Its use is explained here:
> http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-placeholderconfigurer
> This way IT people can modify a properties file which is simpler for them
> than editing the full spring xml.

Make sense.

> The thing is I'm not familiar with Spring so - can we use this approach
> using the customized XML config ?

After a quick read of the documentation, it looks like it would work
when using the ApplicationContext, FtpServer currently only uses a
BeanFactory. Feel free to open a JIRA issue for M4 to investigate
this.

/niklas

Re: Property files with Spring Configuration (PropertyPlaceholderConfigurer)

by Niklas Gustavsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Sep 7, 2008 at 10:05 PM, Niklas Gustavsson <niklas@...> wrote:
> On Fri, Sep 5, 2008 at 12:53 PM, David Latorre <dvlato@...> wrote:
> After a quick read of the documentation, it looks like it would work
> when using the ApplicationContext, FtpServer currently only uses a
> BeanFactory. Feel free to open a JIRA issue for M4 to investigate
> this.

I did some quick testing on this, and using ApplicationContext works
as expected. Of course, since our schema is typed, you will run into
troubles if using our custom elements, for example, setting the port
on a nio-listener using a property won't work as the schema is
expecting an integer. However, using extension elements
(<listener><beans:bean...) works perfectly. I haven't commited
anything yet as this adds in another dependency. What do you think, do
you want this in FtpServer?

/niklas

Twice SSLContext.getInstance(protocol) ?

by Jeroen Cranendonk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

This is in slightly older code, so might already be fixed (can't check from
my workplace).

In DefaultSslConfiguration I find:
        // create SSLContext
>>>>        ctx = SSLContext.getInstance(protocol);
       
        KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();

        // wrap key managers to allow us to control their behavior
(FTPSERVER-93)
        for (int i = 0; i < keyManagers.length; i++) {
          if(ClassUtils.extendsClass(keyManagers[i].getClass(),
"javax.net.ssl.X509ExtendedKeyManager")) {
         keyManagers[i] = new
ExtendedAliasKeyManager(keyManagers[i], keyAlias);
          } else if(keyManagers[i] instanceof X509KeyManager) {
         keyManagers[i] = new AliasKeyManager(keyManagers[i],
keyAlias);
          }
        }
       
        // create SSLContext
>>>>        ctx = SSLContext.getInstance(protocol);

Looks to me like ctx gets initialized twice with no good reason :)

If this is already fixed, ignore me ;)

Cheers!
Jeroen




_______________________________________________________________________________________________
Help save paper! Do you really need to print this email?

Aan de inhoud van dit bericht kunnen alleen rechten ten opzichte van Sdu Identification B.V.
worden ontleend, indien zij door rechtsgeldig ondertekende stukken worden ondersteund.
De informatie in dit e-mailbericht is van vertrouwelijke aard en alleen bedoeld voor gebruik
door geadresseerde. Als u een bericht onbedoeld heeft ontvangen, wordt u verzocht de
verzender hiervan in kennis te stellen en het bericht te vernietigen zonder te vermenigvuldigen
of andersoortig te gebruiken.

The contents of this electronic mail message are only binding upon Sdu Identification B.V.,
if the contents of the message are accompanied by a lawfully recognized type of signature.
The contents of this electronic mail message are privileged and confidential and are intended
only for use by the addressee. If you have received this electronic mail message by error,
please notify the sender and delete the message without reproducing it and using it in any way.


Re: Twice SSLContext.getInstance(protocol) ?

by Niklas Gustavsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 9/8/08, Jeroen Cranendonk <jeroen.cranendonk@...> wrote:
>  Looks to me like ctx gets initialized twice with no good reason :)

It's still in there. While doing no harm (besides the performance
issue calling the factory twice) it's still useless. I'll get rid of
it when I'm back home. Thanks!

/niklas

Re: Property files with Spring Configuration (PropertyPlaceholderConfigurer)

by Niklas Gustavsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Sep 7, 2008 at 11:17 PM, Niklas Gustavsson <niklas@...> wrote:

> On Sun, Sep 7, 2008 at 10:05 PM, Niklas Gustavsson <niklas@...> wrote:
>> On Fri, Sep 5, 2008 at 12:53 PM, David Latorre <dvlato@...> wrote:
>> After a quick read of the documentation, it looks like it would work
>> when using the ApplicationContext, FtpServer currently only uses a
>> BeanFactory. Feel free to open a JIRA issue for M4 to investigate
>> this.
>
> I did some quick testing on this, and using ApplicationContext works
> as expected. Of course, since our schema is typed, you will run into
> troubles if using our custom elements, for example, setting the port
> on a nio-listener using a property won't work as the schema is
> expecting an integer. However, using extension elements
> (<listener><beans:bean...) works perfectly. I haven't commited
> anything yet as this adds in another dependency. What do you think, do
> you want this in FtpServer?

I've commited support for this:
https://issues.apache.org/jira/browse/FTPSERVER-173

/niklas
LightInTheBox - Buy quality products at wholesale price!