i have refered this answer and tried to pass dynamic file pattern
applicationContext to set environment variables and and calling SI Gateway
public class TestSpringIntegration {
public TestSpringIntegration() {
super();
}
public static void main(String[] args) {
TestSpringIntegration testSpringIntegration = new TestSpringIntegration();
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("SI-filters_files.xml");
setEnvironment(context);
// context.refresh();
ServiceGateway gateway =
context.getBean("inboundGateway",ServiceGateway.class);
}
private static void setEnvironment(final ConfigurableApplicationContext ctx) {
String name = "server_text1";
final StandardEnvironment env = new StandardEnvironment();
final Properties props = new Properties();
props.setProperty("filename.pattern", "'" + name + "'");
// props.setProperty("ftp.local.dir", ftpMetaData.getLocalDirectory());
final PropertiesPropertySource pps = new PropertiesPropertySource("ftpprops", props);
env.getPropertySources().addLast(pps);
ctx.setEnvironment(env);
}
}
this is my SI-filters_files.xml I have set environment properties above to get dynamic filePattern in file adapter.
<int:channel id="requestChannel" />
<int:channel id="deadLetterChannel" />
<int:channel id="outboundChannel" />
<int:gateway id="inboundGateway" service-interface="test.ServiceGateway"
default-request-channel="requestChannel" default-reply-timeout="5000" />
<file:inbound-channel-adapter id="filesIn"
directory="file://<IP_ADDRESS>/sharedLocation/" filename-pattern="${filename.pattern}"
channel="requestChannel" auto-startup="true">
<int:poller id="poller" fixed-delay="5000" />
</file:inbound-channel-adapter>
<int:service-activator input-channel="requestChannel"
output-channel="outboundChannel" ref="handler" />
<bean id="handler" class="test.FileHandler" />
<file:outbound-channel-adapter id="outboundChannel"
directory="file://E:/" />
Below is the exception I am getting:
2016-11-30 10:17:59 INFO ClassPathXmlApplicationContext:581 - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@dcf3e99: startup date [Wed Nov 30 10:17:59 CST 2016]; root of context hierarchy 2016-11-30 10:17:59 INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from class path resource [SI-filters_files.xml] 2016-11-30 10:17:59 INFO PropertiesFactoryBean:172 - Loading properties file from URL [jar:file:/C:/Users/F1038/.m2/repository/org/springframework/integration/spring-integration-core/4.3.5.RELEASE/spring-integration-core-4.3.5.RELEASE.jar!/META-INF/spring.integration.default.properties] 2016-11-30 10:17:59 INFO IntegrationRegistrar:330 - No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created. 2016-11-30 10:17:59 INFO DefaultListableBeanFactory:818 - Overriding bean definition for bean 'outboundChannel' with a different definition: replacing [Generic bean: class [org.springframework.integration.channel.DirectChannel]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.integration.channel.DirectChannel]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] 2016-11-30 10:17:59 WARN ClassPathXmlApplicationContext:549 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.integration.file.config.FileListFilterFactoryBean#0' defined in null: Could not resolve placeholder 'filename.pattern' in string value "${filename.pattern}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'filename.pattern' in string value "${filename.pattern}" Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.integration.file.config.FileListFilterFactoryBean#0' defined in null: Could not resolve placeholder 'filename.pattern' in string value "${filename.pattern}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'filename.pattern' in string value "${filename.pattern}" at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223) at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180) at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:152) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at test.TestSpringIntegration.main(Unknown Source) Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'filename.pattern' in string value "${filename.pattern}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:219) at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:193) at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282) at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:209) at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141) at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82) at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:220)