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

时间:2015-02-03 06:15:35

标签: 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)

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

这里有任何帮助。

-Vaibhav

1 个答案:

答案 0 :(得分:8)

我们的测试服务器上有类似的问题。看起来像文件权限的问题,即Spring Batch Admin尝试为" target / config"创建目录结构,但不允许用户创建目录。

这是造成问题的链条:

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>

检查入站通道适配器的文档会显示以下内容(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>

和(!)

 <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>

因此,结果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.");

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

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

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

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