Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't initialize classes annotated with @Repository after upgrade to Spring Boot 3.10

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   
like image 698
Cristian Avatar asked Sep 05 '25 03:09

Cristian


1 Answers

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>
like image 114
Mohit Sharma Avatar answered Sep 07 '25 23:09

Mohit Sharma