Spring批源目录[target/config]不存在

vai*_*hav 5 configuration spring-batch spring-batch-admin

我有一个spring批处理应用程序,其属性文件batch-default.properties设置为

batch.job.configuration.file.dir =目标/配置

现在这个应用程序在我的本地机器上运行良好,即使我没有任何这样的目录,但是当我尝试在我的集成服务器上部署相同时,我收到错误:

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)
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过类似的问题?

这里有任何帮助.

-Vaibhav

小智 8

我们的测试服务器上有类似的问题.看起来像文件的权限,即Spring Batch的管理员试图创建"目标/配置"目录结构的问题,但不允许用户创建目录.

这是导致问题的链条:

META-INF/spring/batch/bootstrap/integration/configuration-context.xml 包含引用属性的文件轮询器的定义:

<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>
Run Code Online (Sandbox Code Playgroud)

检查入站通道适配器的文档会显示以下内容(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) e.g.:
                    directory="file:/absolute/input" or directory="file:relative/input"]]></xsd:documentation>
                </xsd:annotation>            
            </xsd:attribute>
Run Code Online (Sandbox Code Playgroud)

和(!)

 <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>
Run Code Online (Sandbox Code Playgroud)

因此,结果auto-create-directory是正确的,Spring正在尝试在服务器的shell路径上的某个位置创建(相对)目录结构.

对于错误消息,检查java类 org.springframework.integration.file.FileReadingMessageSource给出了解释:

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

javadoc java.io.File.mkdirs()说:

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
Run Code Online (Sandbox Code Playgroud)

所以会发生什么,mkdirs()返回"false",因为他无法创建目录.以下exists()也将返回"false",返回原始帖子中所述的错误消息.

您可以使用绝对路径将参数设置为现有的可写目录,如"/ tmp".不幸的是,如果将作业定义存储在类路径上,我不知道这个春季批处理功能应该如何工作; 不使用文件轮询器而是使用"类路径感知"文件轮询器更有意义...