Java ClassNotFoundException:<;文件>;用于Spring批处理作业

Java ClassNotFoundException:<;文件>;用于Spring批处理作业,java,spring,spring-batch,Java,Spring,Spring Batch,我正在使用SpringCommandLineJobRunner从命令行(批处理文件)运行批处理作业。作业失败,出现classpath:/application.xml的ClassNotFoundException。然而,在日志的前面,它说它为同一个文件加载了51个bean定义 已成功加载bean: [2015/12/30 13:43:37.838] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionRea

我正在使用Spring
CommandLineJobRunner
从命令行(批处理文件)运行批处理作业。作业失败,出现
classpath:/application.xml
ClassNotFoundException
。然而,在日志的前面,它说它为同一个文件加载了51个bean定义

已成功加载bean:

[2015/12/30 13:43:37.838] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] 
Loaded 51 bean definitions from location pattern [classpath:/applicationContext.xml]
[2015/12/30 14:39:27.834] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] 
Loaded 51 bean definitions from location pattern [applicationContext.xml]
例外情况:

[2015/12/30 13:43:40.136] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
No XML-based context named classpath:/applicationContext.xml. Trying class-based configuration.

[2015/12/30 13:43:40.138] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
Job Terminated in error: classpath:/applicationContext.xml

java.lang.ClassNotFoundException: classpath:/applicationContext.xml
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)
[2015/12/30 14:39:30.579] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
No XML-based context named applicationContext.xml. Trying class-based configuration.

[2015/12/30 14:39:30.581] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
Job Terminated in error: applicationContext.xml

java.lang.ClassNotFoundException: applicationContext.xml
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)
启动作业的相关批处理代码(
applicationContext.xml
位于配置目录中):


为了响应Aurelian,在批处理文件中从
classpath:/applicationContext.xml
更改为
applicationContext.xml
,将执行以下操作。请注意不同的堆栈跟踪,并且日志文件的两个成功位置的文件名都发生了更改:

已成功加载bean:

[2015/12/30 13:43:37.838] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] 
Loaded 51 bean definitions from location pattern [classpath:/applicationContext.xml]
[2015/12/30 14:39:27.834] [main] [DEBUG] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] 
Loaded 51 bean definitions from location pattern [applicationContext.xml]
例外情况:

[2015/12/30 13:43:40.136] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
No XML-based context named classpath:/applicationContext.xml. Trying class-based configuration.

[2015/12/30 13:43:40.138] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
Job Terminated in error: classpath:/applicationContext.xml

java.lang.ClassNotFoundException: classpath:/applicationContext.xml
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)
[2015/12/30 14:39:30.579] [main] [INFO] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
No XML-based context named applicationContext.xml. Trying class-based configuration.

[2015/12/30 14:39:30.581] [main] [ERROR] [org.springframework.batch.core.launch.support.CommandLineJobRunner] 
Job Terminated in error: applicationContext.xml

java.lang.ClassNotFoundException: applicationContext.xml
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:291)
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:588)

日志:

您尝试过在applicationContext.xml前面不使用“classpath:/”指令吗?@aurelian我用稍微不同的行为编辑了这个问题。让我感到困惑的是,同一个文件名在两个地方使用,但在第一次使用时却成功了。您能否尝试将applicationContext.xml的名称更改为jobContext.xml?org.springframework.beans.factory.xml.XmlBeanDefinitionReader成功加载的applicationContext.xml可能位于依赖项jar中,而不是您期望的。已更改为jobContext.xml,并将其作为参数传递给CommandLineJobRunner。成功加载bean和异常的文件名都发生了更改,在其他方面与上述编辑后的堆栈跟踪相同。