Spring package Source directory [target / config] does not exist

I have a spring batch application that has batch-default.properties properties file configured as

batch.job.configuration.file.dir = target / configurations

Now this application works well on my local machine, although I do not have such a directory, but when I try to deploy it to my integration server, I get an error message:

Cannot resolve reference to bean 'org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0.source' while setting bean property 'source'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean#0.source': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Source directory [target/config] does not exist. at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417) 

Has anyone encountered a similar problem?

Any help stated here.

-Vaibhav

+5
source share
1 answer

We had a similar problem on our test server. Looks like a file permissions issue, i.e. Spring Batch Admin is trying to create a directory structure for "target / config", but the user is not allowed to create directories.

This is the chain causing the problem:

META-INF/spring/batch/bootstrap/integration/configuration-context.xml contains a file polar definition that refers to a property:

 <file:inbound-channel-adapter directory="${batch.job.configuration.file.dir}" channel="job-configuration-files" filename-pattern=".*\.xml"> <poller max-messages-per-poll="1" cron="5/1 * * * * *" /> </file:inbound-channel-adapter> 

Checking the documentation of the inbound adapter channel shows the following (spring-integration-file-2.1.xsd):

  <xsd:attribute name="directory" type="xsd:string" use="required"> <xsd:annotation> <xsd:documentation><![CDATA[Specifies the input directory (The directory to poll from) eg: directory="file:/absolute/input" or directory="file:relative/input"]]></xsd:documentation> </xsd:annotation> </xsd:attribute> 

and (!)

  <xsd:attribute name="auto-create-directory" type="xsd:string" default="true"> <xsd:annotation> <xsd:documentation> Specify whether to automatically create the source directory if it does not yet exist when this adapter is being initialized. The default value is 'true'. If set to 'false' and the directory does not exist upon initialization, an Exception will be thrown. </xsd:documentation> </xsd:annotation> </xsd:attribute> 

So, as a result, auto-create-directory true, and Spring is trying to create a (relative) directory structure somewhere in the path of your server shell.

For an error message, checking the java class org.springframework.integration.file.FileReadingMessageSource class gives an explanation:

 if (!this.directory.exists() && this.autoCreateDirectory) { this.directory.mkdirs(); } Assert.isTrue(this.directory.exists(), "Source directory [" + directory + "] does not exist."); 

The javadoc java.io.File.mkdirs() says:

 public boolean mkdirs() Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. Returns: true if and only if the directory was created, along with all necessary parent directories; false otherwise 

So what happens, mkdirs () returns false because it could not create a directory. The following exists () also returns false, returning an error message, as indicated in the original message.

A workaround is to set the parameter to an existing and writable directory, for example, "/ tmp" using an absolute path. Unfortunately, I have no idea how this Spring function should work if you save your job definitions in the classpath; it would be wiser not to use the file field, but to use the "polpath-aware" file poller ...

+6
source

Source: https://habr.com/ru/post/1212505/


All Articles