简体   繁体   中英

jndi look up for DefaultFtpSessionFactory

I have ftp connection properties in .properties file and following code for spring bean.

<bean id="ftpConnectionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
        <property name="host" value="${ftp.host}"/>
        <property name="port" value="${ftp.port}"/>
        <property name="username" value="${ftp.username}"/>
        <property name="password" value="${ftp.password}"/>
    </bean>

Above method does work using properties file inside web app and placeholder configuration. But what I want is to keep these properties in server, let's say tomcat context.xml file.

I have spring integration which uses this factory.

<int-ftp:outbound-channel-adapter id="ftpOutbound"
        channel="ftpChannel"
        remote-directory="${ftp.remoteDir}" 
        remote-file-separator="\"
        session-factory="ftpConnectionFactory"
         />

Is there a way that I can externalize these properties in server and look up using jndi. For datasource I am currently doing it. But I don't know how to do it for session factory. The reason why I want to do this is to hide the password and other details.

You could use a PropertyPlaceholderConfigurer as follows

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

See more examples at 5.8.2 Customizing configuration metadata with a BeanFactoryPostProcessor and Spring PropertyPlaceholderConfigurer Example

If Tomcat can correctly bind the object to the JNDI from context.xml , there is no difference to get access to that object from JNDI lookup as you do it for DataSource .

Show, please, how you do it for DataSource from Spring, and how you configure ftpConnectionFactory , and I'll try to help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM