我已经通过 tomcat 中的 war 文件部署了一个 spring 批处理。我在服务器启动时使用 ContextListener 运行批处理。
批处理启动正常,但在数据库初始化期间 db 脚本未运行。该脚本位于 WEB-INF/lib 文件夹中的 jar 文件中。这是配置 xml 中的代码部分 -
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="jar:file:org/springframework/batch/core/schema-drop-mysql.sql" />
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql" />
</jdbc:initialize-database>
Run Code Online (Sandbox Code Playgroud)
它给了我以下例外 -
java.io.FileNotFoundException:无法在 org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141) 处打开 ServletContext 资源 [/org/springframework/batch/core/schema-drop-mysql.sql]在 org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:132) 在 org.springframework.jdbc.datasource.init.ScriptUtils.readScript(ScriptUtils.java:278) 在 org.springframework.jdbc.datasource .init.ScriptUtils.executeSqlScript(ScriptUtils.java:438) ... 32 更多