Spring 找不到元素 'beans' 的声明
Spring cannot find the declaration of element 'beans'
我的 spring 应用程序启动,尝试创建 H2 数据库,然后崩溃并出现以下两个错误。我该如何解决?
第一个错误:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 15 in XML document from
class path resource [org/springframework/jdbc/support/sql-error-codes.xml] is invalid; nested exception
is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
该文件的第 15 行如下。是否可以手动包含 spring-beans-2.0.dtd?这是一个有效的 link 但可能是防火墙阻止了它。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!--
...
-->
<beans>
第二个错误:
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL
grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by
JOB_INSTANCE_ID desc]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table
"BATCH_JOB_INSTANCE" not found; SQL statement:
SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by
JOB_INSTANCE_ID desc [42102-199]
我尝试切换 spring 设置,例如 spring.batch.initialize-schema=always
,但没有效果。
问题是文件编码。 运行 带有 -Dfile.encoding=ISO8859-1
的 jar 解决了它。这是特定于环境的,可能并不适合所有人。
我的 spring 应用程序启动,尝试创建 H2 数据库,然后崩溃并出现以下两个错误。我该如何解决?
第一个错误:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 15 in XML document from
class path resource [org/springframework/jdbc/support/sql-error-codes.xml] is invalid; nested exception
is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
该文件的第 15 行如下。是否可以手动包含 spring-beans-2.0.dtd?这是一个有效的 link 但可能是防火墙阻止了它。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<!--
...
-->
<beans>
第二个错误:
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL
grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by
JOB_INSTANCE_ID desc]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table
"BATCH_JOB_INSTANCE" not found; SQL statement:
SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? order by
JOB_INSTANCE_ID desc [42102-199]
我尝试切换 spring 设置,例如 spring.batch.initialize-schema=always
,但没有效果。
问题是文件编码。 运行 带有 -Dfile.encoding=ISO8859-1
的 jar 解决了它。这是特定于环境的,可能并不适合所有人。