英文:
Can't initialize classes annotated with @Repository after upgrade to Spring Boot 3.10
问题
我们决定从Spring 2.7.0升级到Spring 3.x。首先,我升级到了Spring 3.0.x,但由于一个Spring的错误,bean没有被初始化,所以我切换到了3.1.0。我修复了所有的编译错误,将javax改为了jakarta,升级了spring-security配置等等。现在,应用程序启动但在初始化时崩溃。以下是日志片段:
[background-preinit] Version.<clinit>:21 - HV000001: Hibernate Validator 8.0.0.Final
[main] StartupInfoLogger.logStarting:51 - Starting ContentApplication using Java 17.0.2 with PID 3564
[main] SpringApplication.logStartupProfileInfo:639 - The following 1 profile is active: "local"
[main] RepositoryConfigurationDelegate.registerRepositoriesIn:138 - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[main] RepositoryConfigurationDelegate.registerRepositoriesIn:208 - Finished Spring Data repository scanning in 550 ms. Found 37 JPA repository interfaces.
[main] TomcatWebServer.initialize:108 - Tomcat initialized with port(s): 8080 (http)
[main] ServletWebServerApplicationContext.prepareWebApplicationContext:291 - Root WebApplicationContext: initialization completed in 5214 ms
[main] Version.logVersion:44 - HHH000412: Hibernate ORM core version 6.2.2.Final
[main] Environment.<clinit>:191 - HHH000406: Using bytecode reflection optimizer
[main] BytecodeProviderInitiator.buildBytecodeProvider:53 - HHH000021: Bytecode provider name : bytebuddy
[main] DialectFactoryImpl.logSelectedDialect:93 - HHH035001: Using dialect: org.hibernate.dialect.SQLServerDialect, version: 12.0
[main] QueryEnhancerFactory.<clinit>:47 - Hibernate is in classpath; If applicable, HQL parser will be used.
ANTLR Tool version 4.10.1 used for code generation does not match the current runtime version 4.9.3
ANTLR Runtime version 4.10.1 used for parser compilation does not match the current runtime version 4.9.3
[main] TomcatStarter.onStartup:60 - Error starting Tomcat context.
错误如下:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in packagename.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: null
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.data.jpa.repository.query.HqlQueryParser.parseQuery(HqlQueryParser.java:48)
at org.springframework.data.jpa.repository.query.HqlQueryParser.parse(HqlQueryParser.java:63)
at org.springframework.data.jpa.repository.query.JpaQueryParserSupport$ParseState.lambda$new$0(JpaQueryParserSupport.java:182)
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:187)
at org.springframework.data.jpa.repository.query.HqlLexer.<clinit>(HqlLexer.java:1314)
... 222 common frames omitted
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
... 224 common frames omitted
英文:
We decided to start upgrading from Spring 2.7.0 to Spring 3.x.
First I upgraded to Spring 3.0.x but, due to a spring bug, the beans were not initialized so I switched to 3.1.0.
I fixed all the compilation errors, changed javax to jakarta, upgraded the spring-security configuration and so forth.
Now, the application starts but crashes at initialization. Here's a log snippet.
[background-preinit] Version.<clinit>:21 - HV000001: Hibernate Validator 8.0.0.Final
[main] StartupInfoLogger.logStarting:51 - Starting ContentApplication using Java 17.0.2 with PID 3564
[main] SpringApplication.logStartupProfileInfo:639 - The following 1 profile is active: "local"
[main] RepositoryConfigurationDelegate.registerRepositoriesIn:138 - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
[main] RepositoryConfigurationDelegate.registerRepositoriesIn:208 - Finished Spring Data repository scanning in 550 ms. Found 37 JPA repository interfaces.
[main] TomcatWebServer.initialize:108 - Tomcat initialized with port(s): 8080 (http)
[main] ServletWebServerApplicationContext.prepareWebApplicationContext:291 - Root WebApplicationContext: initialization completed in 5214 ms
[main] Version.logVersion:44 - HHH000412: Hibernate ORM core version 6.2.2.Final
[main] Environment.<clinit>:191 - HHH000406: Using bytecode reflection optimizer
[main] BytecodeProviderInitiator.buildBytecodeProvider:53 - HHH000021: Bytecode provider name : bytebuddy
[main] DialectFactoryImpl.logSelectedDialect:93 - HHH035001: Using dialect: org.hibernate.dialect.SQLServerDialect, version: 12.0
[main] QueryEnhancerFactory.<clinit>:47 - Hibernate is in classpath; If applicable, HQL parser will be used.
ANTLR Tool version 4.10.1 used for code generation does not match the current runtime version 4.9.3
ANTLR Runtime version 4.10.1 used for parser compilation does not match the current runtime version 4.9.3
[main] TomcatStarter.onStartup:60 - Error starting Tomcat context.
The error is the following
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in packagename.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: null
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.data.jpa.repository.query.HqlQueryParser.parseQuery(HqlQueryParser.java:48)
at org.springframework.data.jpa.repository.query.HqlQueryParser.parse(HqlQueryParser.java:63)
at org.springframework.data.jpa.repository.query.JpaQueryParserSupport$ParseState.lambda$new$0(JpaQueryParserSupport.java:182)
--------------------------------------------------------------------------------------------------------------------------------------
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:187)
at org.springframework.data.jpa.repository.query.HqlLexer.<clinit>(HqlLexer.java:1314)
... 222 common frames omitted
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
... 224 common frames omitted
答案1
得分: 3
始终查看错误日志中的 Caused by:,看起来需要升级 antlr4-runtime jar 到最新版本。使用 mvn dependency:tree 命令检查版本,如果不是最新版本,请更新为最新版本。
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.13.0</version>
</dependency>
英文:
Always looks the Caused by: in the error logs, looks like need to upgrade the antlr4-runtime jar to latest. Check using the mvn dependency:tree about the version, if not update to the latest
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.13.0</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论