gpt4 book ai didi

java - BadSqlGrammarException : bad SQL grammar [SELECT JOB_INSTANCE_ID, BATCH_JOB_INSTANCE 中的 JOB_NAME...] - 不同环境下的不同行为

转载 作者:行者123 更新时间:2023-12-01 18:07:42 34 4
gpt4 key购买 nike

我有来自 2 个不同分支的服务器 #2 和服务器 #3 以及 Sprint Boot 应用程序 jar。

我通过 bitbucket 和所有配置类以及 pom.xml 手动比较了分支 - 代码是相同的(jackson-databind:jar:2.9.10.1 与 jackson-databind:jar:2.9.10.2 的版本除外,这不应该影响问题)。

我比较了两台服务器上的属性文件 - 它们是相同的。

依赖树:

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ ...batch ---
[INFO] ...batch:jar:1.00
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.6.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.0.6.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.6.RELEASE:compile
[INFO] | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] | +- org.springframework:spring-core:jar:5.0.10.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.0.10.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- ...:Logging:jar:15.55:compile
[INFO] | +- log4j:log4j:jar:1.2.17:compile
[INFO] | \- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.springframework.batch:spring-batch-core:jar:4.0.2.RELEASE:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.10.2:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
[INFO] | +- javax.batch:javax.batch-api:jar:1.0:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] | +- org.springframework:spring-aop:jar:5.0.10.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:5.0.10.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.0.10.RELEASE:compile
[INFO] | | \- org.springframework:spring-expression:jar:5.0.10.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:5.0.10.RELEASE:compile
[INFO] +- org.springframework.batch:spring-batch-infrastructure:jar:4.0.2.RELEASE:compile
[INFO] | \- org.springframework.retry:spring-retry:jar:1.2.2.RELEASE:compile
[INFO] +- org.jacoco:org.jacoco.agent:jar:runtime:0.8.3:test
[INFO] +- ....cib.envkit.pojo:pojo-tester:jar:0.0.12:compile
[INFO] | +- org.meanbean:meanbean:jar:2.0.3:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- com.google.guava:guava:jar:20.0:compile
[INFO] | +- org.javassist:javassist:jar:3.22.0-GA:compile
[INFO] | +- com.intellij:annotations:jar:12.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] +- org.glassfish.web:javax.el:jar:2.2.6:compile
[INFO] | \- javax.el:javax.el-api:jar:2.2.5:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- ...:...-Common:jar:15.55:compile
[INFO] | +- ...:...-Common-API:jar:15.55:compile
[INFO] | | \- org.codehaus.jackson:jackson-jaxrs:jar:1.9.13:compile
[INFO] | | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.4.2.Final:compile
[INFO] | +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] | +- org.springframework:spring-context-support:jar:5.0.10.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:4.3.20.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:2.0.11.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:2.0.11.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:5.0.10.RELEASE:compile
[INFO] | | \- org.aspectj:aspectjrt:jar:1.8.13:compile
[INFO] | +- commons-codec:commons-codec:jar:1.11:compile
[INFO] | +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.0.0:compile
[INFO] | | +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] | | +- asm:asm:jar:3.3.1:compile
[INFO] | | +- org.apache.cxf:cxf-core:jar:3.0.0:compile
[INFO] | | | \- org.apache.ws.xmlschema:xmlschema-core:jar:2.1.0:compile
[INFO] | | +- org.apache.cxf:cxf-rt-bindings-soap:jar:3.0.0:compile
[INFO] | | | +- org.apache.cxf:cxf-rt-wsdl:jar:3.0.0:compile
[INFO] | | | | \- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] | | | \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.0:compile
[INFO] | | +- org.apache.cxf:cxf-rt-bindings-xml:jar:3.0.0:compile
[INFO] | | +- org.apache.cxf:cxf-rt-frontend-simple:jar:3.0.0:compile
[INFO] | | \- org.apache.cxf:cxf-rt-ws-addr:jar:3.0.0:compile
[INFO] | | \- org.apache.cxf:cxf-rt-ws-policy:jar:3.0.0:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] | +- com.cyberark.epv.sdk:javapasswordsdk:jar:7.20.110.9:compile
[INFO] | +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:3.0.0:compile
[INFO] | +- org.apache.cxf:cxf-rt-rs-client:jar:3.0.0:compile
[INFO] | +- org.apache.cxf:cxf-rt-ws-security:jar:3.0.2:compile
[INFO] | | +- org.apache.cxf:cxf-rt-security:jar:3.0.2:compile
[INFO] | | | \- org.apache.wss4j:wss4j-ws-security-common:jar:2.0.2:compile
[INFO] | | | +- org.opensaml:opensaml:jar:2.6.1:compile
[INFO] | | | | \- joda-time:joda-time:jar:2.9.9:compile
[INFO] | | | \- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] | | +- org.apache.wss4j:wss4j-ws-security-dom:jar:2.0.2:compile
[INFO] | | +- org.apache.wss4j:wss4j-policy:jar:2.0.2:compile
[INFO] | | | \- org.apache.neethi:neethi:jar:3.0.3:compile
[INFO] | | +- org.apache.wss4j:wss4j-ws-security-stax:jar:2.0.2:compile
[INFO] | | | \- org.apache.wss4j:wss4j-bindings:jar:2.0.2:compile
[INFO] | | \- org.apache.wss4j:wss4j-ws-security-policy-stax:jar:2.0.2:compile
[INFO] | +- org.apache.santuario:xmlsec:jar:2.0.5:compile
[INFO] | | \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] | | +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | +- com.atomikos:transactions-jta:jar:4.0.6:compile
[INFO] | | \- com.atomikos:transactions-api:jar:4.0.6:compile
[INFO] | +- com.atomikos:transactions:jar:3.8.0:compile
[INFO] | | \- org.mockito:mockito-all:jar:1.9.0:compile
[INFO] | +- com.atomikos:transactions-jdbc:jar:4.0.6:compile
[INFO] | +- com.atomikos:atomikos-util:jar:3.8.0:compile
[INFO] | +- com.atomikos:transactions-hibernate3:jar:3.8.0:compile
[INFO] | +- org.glassfish:javax.jms:jar:3.0.1:compile
[INFO] | +- org.springframework:spring-jms:jar:5.0.10.RELEASE:compile
[INFO] | | \- org.springframework:spring-messaging:jar:5.0.10.RELEASE:compile
[INFO] | \- com.ibm.mq:com.ibm.mqjms:jar:7.5.0.8:compile
[INFO] +- org.springframework:spring-web:jar:5.0.10.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.0.6.RELEASE:compile (optional)
[INFO] +- org.projectlombok:lombok:jar:1.18.8:compile
[INFO] +- org.hibernate:hibernate-ehcache:jar:5.2.11.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] | \- net.sf.ehcache:ehcache:jar:2.10.5:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.2.11.Final:compile
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.7.11:compile
[INFO] | \- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.2.11.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] | \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] \- com.oracle:ojdbc6:jar:11.2.0.4:compile

该问题仅发生在服务器 #2 上。

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist 

有jobRepository配置:

@Bean
public JobRepository jobRepository() throws Exception {
MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager());
return mapJobRepositoryFactoryBean.getObject();
}

所以SpringBoot应该使用内存方式。

除了以下内容之外,两个应用程序的输出相同

服务器#2

2020-03-03 16:01:21 INFO  DefaultListableBeanFactory:821 - Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=databaseConfig; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/jpmorgan/ccit/config/DatabaseConfig.class]] 
with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]]||

factoryBeanName=databaseConfig

服务器#3

2020-03-02 17:26:09 INFO  DefaultListableBeanFactory:821 - Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]] 
with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=databaseConfig; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/jpmorgan/ccit/config/DatabaseConfig.class]]||

factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration;

所以我认为问题可能出在 bean 重写上。

我无法在服务器 #3 或本地环境上重现此问题。

当我将 jar 从服务器 #3 复制到服务器 #2 时 – 它工作正常。

当我将 jar 从服务器 #2 复制到服务器 #3 时 – 遇到了同样的问题。

Spring 2.1 的 spring.main.allow-bean-definition-overriding 属性?据我所知,2.0 中默认应该覆盖它。

还有其他建议吗?

<小时/>

一些细节:

我们使用的是自定义属性文件,而不是 application.properties。运行者看起来像:

@SpringBootApplication
public class BatchApplication {
public static void main(String[] args) {
String rootPath = System.getProperty("config.root");
PropertyConfigurator.configure(rootPath + "/batch-log4j.properties");
SpringApplication.run(BatchApplication.class, args);
}
}


@Configuration
@EnableBatchProcessing
@PropertySource(value = {"file:${config.root}/…-batch.properties"}, ignoreResourceNotFound = true)
public class BatchConfig {

不,我无法将 jar 从本地复制到服务器。

不,我无法将 jar 从服务器复制到本地。

<小时/>

更新#1

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:230)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:655)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:690)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:722)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:732)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:787)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:145)
at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution(SimpleJobRepository.java:293)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy87.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy114.run(Unknown Source)
at ....service...BatchService.launchJob(...BatchService.java:68)
at ....service...BatchService.executeJob(...BatchService.java:101)
at ....service....BatchService.run(...BatchService.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:886)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1495)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:698)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:639)
... 47 more
<小时/>

更新#2

有使用 SimpleJobRepository:293 在本地环境上成功运行的屏幕截图。此行来自上面的堆栈跟踪。

SimpleJobRepository:293

如您所见,jobInstanceDao 是 MapJobInstanceDao。

MapJobInstanceDao is in-memory implementation of JobInstanceDao

<小时/>

更新#3

  1. 我更新了 pom.xml 并将 jackson-databind:jar:2.9.10.2 降级为 jackson-databind:jar:2.9.10.1。 -同样的问题
  2. 我找到了将 jar 从服务器 #3 复制到服务器 #2 并运行它的方法 - 服务器 #3 中的 jar 工作正常(使用服务器 #2 中的数据库)
  3. 两个文件的大小相同
  4. 我找到了将这两个文件从服务器下载到本地的方法。 pom.xml 文件相同,spring/springboot/springbatch jar 版本相同
<小时/>

更新#4

服务器#3(成功):

[org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader] - <Registering bean definition for @Bean method org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration.jobRepository()>
[org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Overriding bean definition for bean 'transactionManager' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=databaseConfig; factoryMethodName=transactionManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/.../.../config/DatabaseConfig.class]]>
[org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader] - <Registering bean definition for @Bean method com.........config.DatabaseConfig.jobRepository()>
[org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Overriding bean definition for bean 'jobRepository' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration; factoryMethodName=jobRepository; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=databaseConfig; factoryMethodName=jobRepository; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/.../.../config/DatabaseConfig.class]]>

服务器#2(失败):

[org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader] - <Registering bean definition for @Bean method com.........config.DatabaseConfig.jobRepository()>    [org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader] - <Registered bean definition for imported class 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration'>

[org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader] - [org.springframework.beans.factory.support.DefaultListableBeanFactory] ​​-

所以看起来bean初始化的顺序不同...

最佳答案

该异常看起来像您正在使用的表与使用 JPA/Hibernate 定义的 Java 模型不对应。我看到您使用 Oracle JDBC,所以您使用的是 Oracle 数据库。我非常确定您需要更新数据库架构。您可能知道,使用 Spring boot 和 JPA,您可以使用 spring.jpa.hibernate.ddl-auto 属性在数据库架构上配置 JPA 行为,以验证或创建数据库架构。通常,它可以在application.properties上设置。在您的情况下,将此属性放入您的自定义属性文件中。

spring.jpa.database=mysql
#spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

现在您可以:

  1. 如果您的数据库架构非常稳定,我建议您比较您的数据库架构,并更新不起作用的环境的数据库架构,应用差异以尊重有效的环境。
  2. 如果您仍处于开发阶段,请考虑使用 spring.jpa.hibernate.ddl-auto=create。这样,每次应用程序启动时都会重新创建您的数据库。

希望对您有所帮助。

关于java - BadSqlGrammarException : bad SQL grammar [SELECT JOB_INSTANCE_ID, BATCH_JOB_INSTANCE 中的 JOB_NAME...] - 不同环境下的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60530972/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com