我使用Spring CommandLineJobRunner
从命令行运行批处理作业(批处理文件)。作业失败,ClassNotFoundException
为classpath:/application.xml
。在日志的早些时候,它说它为同一个文件加载了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 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)
启动作业的相关批处理代码(applicationContext.xml
位于config目录中):
SET CURR_DIR=C:\OtherLines\JavaBatchTest\RUS
SET CONFIG_FILES=%CURR_DIR%\build\resources\main\com\rusbatch\config\
SET COMMON_LIB=%CURR_DIR%\lib\*
SET PROJECT_LIB=%CURR_DIR%\build\libs\*
SET LOG4J_CONFIG=%CURR_DIR%\build\resources\main\com\rusbatch\config\log4j.xml
SET LOG_PATH=%CURR_DIR%\logs\
SET JAVA_EXE="C:\Program Files\Java\jre1.8.0_65\bin\java.exe"
SET USER_CLASSPATH=%COMMON_LIB%;%PROJECT_LIB%;%CONFIG_FILES%
%JAVA_EXE% -Xms512m -Xmx1024M -DENV=UNIT -DSYSENV=U -cp %USER_CLASSPATH% -DLOG4J_CONFIG=%LOG4J_CONFIG% -DLOG_PATH=%LOG_PATH% org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/applicationContext.xml updateInspectionDateJob >> logs\%_JOB_NAME%.log
在回复Aurelien时,批处理文件中从classpath:/applicationContext.xml
更改为applicationContext.xml
会执行以下操作。请注意不同的堆栈跟踪以及文件名在日志文件的两个成功位置都已更改:
成功加载bean:
[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 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)