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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top