SpringBoot version: 3.5.0 Hibernate Version: 6.6.15.Final
When i use native image to package my project.I compile successed. But when i run it. Give this fail message:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': org.hibernate.bytecode.spi.BytecodeProvider: Provider org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl not found
more logs:
2025-06-27T16:31:07.413+08:00 INFO 33417 --- [ChainOS-User] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2025-06-27T16:31:07.414+08:00 INFO 33417 --- [ChainOS-User] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.6.15.Final
2025-06-27T16:31:07.416+08:00 INFO 33417 --- [ChainOS-User] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2025-06-27T16:31:07.419+08:00 INFO 33417 --- [ChainOS-User] [ main] com.zaxxer.hikari.HikariDataSource : ChainOS-User-HikariPool - Starting...
2025-06-27T16:31:07.547+08:00 INFO 33417 --- [ChainOS-User] [ main] com.zaxxer.hikari.pool.HikariPool : ChainOS-User-HikariPool - Added connection org.postgresql.jdbc.PgConnection@41b49605
2025-06-27T16:31:07.547+08:00 INFO 33417 --- [ChainOS-User] [ main] com.zaxxer.hikari.HikariDataSource : ChainOS-User-HikariPool - Start completed.
2025-06-27T16:31:07.576+08:00 INFO 33417 --- [ChainOS-User] [ main] org.hibernate.orm.connections.pooling : HHH10001005: Database info:
Database JDBC URL [Connecting through datasource 'HikariDataSource (ChainOS-User-HikariPool)']
Database driver: undefined/unknown
Database version: 17.4
Autocommit mode: undefined/unknown
Isolation level: undefined/unknown
Minimum pool size: undefined/unknown
Maximum pool size: undefined/unknown
2025-06-27T16:31:07.587+08:00 WARN 33417 --- [ChainOS-User] [ main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': org.hibernate.bytecode.spi.BytecodeProvider: Provider org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl not found
2025-06-27T16:31:07.587+08:00 INFO 33417 --- [ChainOS-User] [ main] com.zaxxer.hikari.HikariDataSource : ChainOS-User-HikariPool - Shutdown initiated...
2025-06-27T16:31:07.587+08:00 INFO 33417 --- [ChainOS-User] [ main] com.zaxxer.hikari.HikariDataSource : ChainOS-User-HikariPool - Shutdown completed.
Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': org.hibernate.bytecode.spi.BytecodeProvider: Provider org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl not found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1826)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:373)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:970)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1362)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1351)
at cn.trendai.chain.os.user.interfaces.ChainOsUserApplication.main(ChainOsUserApplication.java:26)
at java.base@21.0.7/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.util.ServiceConfigurationError: org.hibernate.bytecode.spi.BytecodeProvider: Provider org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl not found
at java.base@21.0.7/java.util.ServiceLoader.fail(ServiceLoader.java:593)
at java.base@21.0.7/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219)
at java.base@21.0.7/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
at java.base@21.0.7/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base@21.0.7/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base@21.0.7/java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1491)
at java.base@21.0.7/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.loadAll(AggregatedServiceLoader.java:123)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.getAll(AggregatedServiceLoader.java:112)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:241)
at org.hibernate.bytecode.internal.BytecodeProviderInitiator.initiateService(BytecodeProviderInitiator.java:51)
at org.hibernate.bytecode.internal.BytecodeProviderInitiator.initiateService(BytecodeProviderInitiator.java:22)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:70)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:47)
at org.hibernate.boot.internal.DefaultSessionFactoryBuilderService.createSessionFactoryBuilder(DefaultSessionFactoryBuilderService.java:26)
at org.hibernate.boot.internal.MetadataImpl.getSessionFactoryBuilder(MetadataImpl.java:175)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1513)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:419)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:400)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1873)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1822)
... 16 more
Comment From: HydroCarbon
It's a multi module project. have those plugin in root pom:
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
and those plugin in Main application pom:
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
And i try to add reachable metadata with:
<configuration>
<metadataRepository>
<enabled>true</enabled>
<version>0.3.22</version>
</metadataRepository>
<verbose>true</verbose>
</configuration>
It still has this error message.
I also try to this hint:
@Configuration
@ImportRuntimeHints(DataRuntimeHint.class)
public class DataRuntimeHint implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(BytecodeProviderImpl.class, MemberCategory.values());
}
}
but failed too.
How to fix it?
Comment From: wilkinsona
The BytecodeProvider should be automatically disabled by spring-orm as it isn't needed in a native image. It's disabled by its native-image.properties file. We'll transfer this to the Spring Framework issue tracker so that they can investigate why this doesn't appear to be working.
Comment From: sdeleuze
@HydroCarbon What exact version and distribution of GraalVM native image are you using ?
Comment From: wengmy
I'm having a similar issue on my MacBook (M1 chip). SpringBoot: 3.4.7 Hibernate: 6.6.18.Final GraalVM:
java 21.0.7 2025-04-15 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 21.0.7+8.1 (build 21.0.7+8-LTS-jvmci-23.1-b60)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.7+8.1 (build 21.0.7+8-LTS-jvmci-23.1-b60, mixed mode, sharing)
Stacktrace:
Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': org.hibernate.bytecode.spi.BytecodeProvider: org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl Unable to get public no-arg constructor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1826)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:373)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:970)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
at com.example.graalvm.GraalvmApplicationKt.main(GraalvmApplication.kt:13)
at java.base@21.0.7/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.util.ServiceConfigurationError: org.hibernate.bytecode.spi.BytecodeProvider: org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl Unable to get public no-arg constructor
at java.base@21.0.7/java.util.ServiceLoader.fail(ServiceLoader.java:586)
at java.base@21.0.7/java.util.ServiceLoader.getConstructor(ServiceLoader.java:679)
at java.base@21.0.7/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1240)
at java.base@21.0.7/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base@21.0.7/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base@21.0.7/java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1491)
at java.base@21.0.7/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.loadAll(AggregatedServiceLoader.java:123)
at org.hibernate.boot.registry.classloading.internal.AggregatedServiceLoader$ClassPathAndModulePathAggregatedServiceLoader.getAll(AggregatedServiceLoader.java:112)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:241)
at org.hibernate.bytecode.internal.BytecodeProviderInitiator.initiateService(BytecodeProviderInitiator.java:51)
at org.hibernate.bytecode.internal.BytecodeProviderInitiator.initiateService(BytecodeProviderInitiator.java:22)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:238)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:70)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.<init>(SessionFactoryBuilderImpl.java:47)
at org.hibernate.boot.internal.DefaultSessionFactoryBuilderService.createSessionFactoryBuilder(DefaultSessionFactoryBuilderService.java:26)
at org.hibernate.boot.internal.MetadataImpl.getSessionFactoryBuilder(MetadataImpl.java:175)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1513)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:390)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:419)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:400)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1873)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1822)
... 16 more
Caused by: java.lang.NoSuchMethodException: org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl.<init>()
at java.base@21.0.7/java.lang.Class.checkMethod(DynamicHub.java:1078)
at java.base@21.0.7/java.lang.Class.getConstructor0(DynamicHub.java:1241)
at java.base@21.0.7/java.lang.Class.getConstructor(DynamicHub.java:2442)
at java.base@21.0.7/java.util.ServiceLoader$1.run(ServiceLoader.java:666)
at java.base@21.0.7/java.util.ServiceLoader$1.run(ServiceLoader.java:663)
at java.base@21.0.7/java.security.AccessController.executePrivileged(AccessController.java:114)
at java.base@21.0.7/java.security.AccessController.doPrivileged(AccessController.java:571)
at java.base@21.0.7/java.util.ServiceLoader.getConstructor(ServiceLoader.java:674)
... 42 more
Simple repo to reproduce: https://github.com/wengmy/graalvm/tree/main
Plus, in the logs of nativeCompile, I did see BytecodeProvider related messages, but seems not working at last?
> Task :nativeCompile
[native-image-plugin] GraalVM Toolchain detection is disabled
[native-image-plugin] GraalVM location read from environment variable: JAVA_HOME
[native-image-plugin] Native Image executable path: /Users/xxx/Library/Java/JavaVirtualMachines/graalvm-jdk-21.0.7/Contents/Home/lib/svm/bin/native-image
Warning: The option '-H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider' is experimental and must be enabled via '-H:+UnlockExperimentalVMOptions' in the future.
Warning: Please re-evaluate whether any experimental option is required, and either remove or unlock it. The build output lists all active experimental options, including where they come from and possible alternatives. If you think an experimental option should be considered as stable, please file an issue.
------------------------------------------------------------------------------------------------------------------------
1 experimental option(s) unlocked:
- '-H:ServiceLoaderFeatureExcludeServices' (origin(s): 'META-INF/native-image/org.springframework/spring-orm/native-image.properties' in 'file:///Users/xxx/.gradle/caches/modules-2/files-2.1/org.springframework/spring-orm/6.2.8/3bfe2a04c09ad1d7738b16e6e4636a7255be3af8/spring-orm-6.2.8.jar')
------------------------------------------------------------------------------------------------------------------------
Comment From: kcello
I have the same problem, I tried with all the versions of springboot 3.4.x and 3.5.x but I can't solve it. I used GraalVM comunity 17 - 21 - 24 and I don't know where to look anymore
Comment From: HydroCarbon
@HydroCarbon What exact version and distribution of GraalVM native image are you using ?
❯ java -version openjdk version "21.0.7" 2025-04-15 LTS OpenJDK Runtime Environment Liberica-NIK-23.1.7-1 (build 21.0.7+9-LTS) OpenJDK 64-Bit Server VM Liberica-NIK-23.1.7-1 (build 21.0.7+9-LTS, mixed mode, sharing)
Comment From: HydroCarbon
The
BytecodeProvidershould be automatically disabled by spring-orm as it isn't needed in a native image. It's disabled by its native-image.properties file. We'll transfer this to the Spring Framework issue tracker so that they can investigate why this doesn't appear to be working.
I add this build arg,but still has same error:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs>
<buildArg>-H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider
</buildArg>
</buildArgs>
</configuration>
</plugin>
Comment From: HydroCarbon
@HydroCarbon What exact version and distribution of GraalVM native image are you using ?
This is more logs for compile:
========================================================================================================================
GraalVM Native Image: Generating 'user-interface' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing... (7.4s @ 0.37GB)
Java version: 21.0.7+9-LTS, vendor version: Liberica-NIK-23.1.7-1
Graal compiler: optimization level: 2, target machine: armv8-a
C compiler: cc (apple, arm64, 17.0.0)
Garbage collector: Serial GC (max heap size: 80% of RAM)
3 user-specific feature(s):
- com.oracle.svm.thirdparty.gson.GsonFeature
- org.eclipse.angus.activation.nativeimage.AngusActivationFeature
- org.springframework.aot.nativex.feature.PreComputeFieldFeature
------------------------------------------------------------------------------------------------------------------------
1 experimental option(s) unlocked:
- '-H:ServiceLoaderFeatureExcludeServices' (origin(s): 'META-INF/native-image/org.springframework/spring-orm/native-image.properties' in 'file:///Users/hydro/.m2/repository/org/springframework/spring-orm/6.2.7/spring-orm-6.2.7.jar', command line)
------------------------------------------------------------------------------------------------------------------------
Comment From: HydroCarbon
@HydroCarbon What exact version and distribution of GraalVM native image are you using ?
@sdeleuze https://github.com/spring-projects/spring-framework/issues/35118#issuecomment-3014673156
Comment From: sdeleuze
As far as I can tell, the error is triggered by the metadata generated by the GraalVM tracing agent. Not sure why exactly, but this issue does not look like on Spring side.
Why do you need those generated metadata? Can you reproduce the issue without?
Comment From: ma-hab
I have 2 projects both using spring-boot 3.5.3 and hibernate 6.6.18.Final. Both have hibernate and native-build plugins defined the same way:
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>${hibernate.version}</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<buildArgs>-H:+StaticExecutableWithDynamicLibC</buildArgs>
</configuration>
<executions>
<execution>
<id>build-image</id>
<goals>
<!-- this allows build on multi module projects -->
<goal>compile-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
In one project I am getting the same error OP mentioned while in another everything works fine and I have no idea why. Both are built with the same docker image ghcr.io/graalvm/native-image-community:21.0.2
Working project native build logs:
#12 146.4 For detailed information and explanations on the build output, visit:
#12 146.4 https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
#12 146.4 ------------------------------------------------------------------------------------------------------------------------
#12 152.3 [1/8] Initializing... (13.4s @ 0.43GB)
#12 152.3 Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
#12 152.3 Graal compiler: optimization level: 2, target machine: x86-64-v3
#12 152.3 C compiler: gcc (redhat, x86_64, 11.4.1)
#12 152.3 Garbage collector: Serial GC (max heap size: 80% of RAM)
#12 152.3 3 user-specific feature(s):
#12 152.3 - com.oracle.svm.thirdparty.gson.GsonFeature
#12 152.3 - org.eclipse.angus.activation.nativeimage.AngusActivationFeature
#12 152.3 - org.springframework.aot.nativex.feature.PreComputeFieldFeature
#12 152.3 ------------------------------------------------------------------------------------------------------------------------
#12 152.3 2 experimental option(s) unlocked:
#12 152.3 - '-H:ServiceLoaderFeatureExcludeServices' (origin(s): 'META-INF/native-image/org.springframework/spring-orm/native-image.properties' in 'file:///home/builder/.m2/repository/org/springframework/spring-orm/6.2.8/spring-orm-6.2.8.jar')
#12 152.3 - '-H:+StaticExecutableWithDynamicLibC' (origin(s): command line)
#12 152.3 ------------------------------------------------------------------------------------------------------------------------
#12 152.3 Build resources:
#12 152.3 - 12.73GB of memory (40.9% of 31.12GB system memory, determined at start)
#12 152.3 - 16 thread(s) (100.0% of 16 available processor(s), determined at start)
#12 175.6 SLF4J(W): No SLF4J providers were found.
#12 175.6 SLF4J(W): Defaulting to no-operation (NOP) logger implementation
#12 175.6 SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
#12 282.9 [2/8] Performing analysis... [*****] (130.2s @ 4.29GB)
#12 282.9 45,635 reachable types (93.0% of 49,057 total)
#12 282.9 68,216 reachable fields (62.7% of 108,729 total)
#12 283.0 223,956 reachable methods (63.5% of 352,502 total)
#12 283.0 13,893 types, 4,992 fields, and 24,281 methods registered for reflection
#12 283.0 65 types, 67 fields, and 57 methods registered for JNI access
#12 283.0 4 native libraries: dl, pthread, rt, z
#12 302.8 [3/8] Building universe... (19.7s @ 6.19GB)
#12 313.5 [4/8] Parsing methods... [***] (10.7s @ 4.08GB)
#12 322.5 [5/8] Inlining methods... [****] (7.4s @ 6.04GB)
#12 409.5 [6/8] Compiling methods... [*********] (86.9s @ 4.37GB)
#12 436.9 [7/8] Layouting methods... [*****] (27.4s @ 4.63GB)
#12 468.3 [8/8] Creating image... [*****] (30.9s @ 3.55GB)
#12 468.3 102.55MB (49.72%) for code area: 149,868 compilation units
#12 468.3 103.27MB (50.07%) for image heap: 882,021 objects and 557 resources
#12 468.3 433.53kB ( 0.21%) for other data
#12 468.3 206.24MB in total
#12 468.3 ------------------------------------------------------------------------------------------------------------------------
#12 468.3 Top 10 origins of code area: Top 10 object types in image heap:
#12 468.3 16.10MB hibernate-core-6.6.18.Final.jar 31.25MB byte[] for code metadata
#12 468.3 15.99MB java.base 14.26MB byte[] for java.lang.String
#12 468.3 7.27MB jdk.proxy4 12.93MB byte[] for embedded resources
#12 468.3 4.59MB tomcat-embed-core-10.1.42.jar 11.32MB java.lang.Class
#12 468.3 4.53MB java.desktop 8.55MB java.lang.String
#12 468.3 4.10MB java.xml 3.83MB com.oracle.svm.core.hub.DynamicHubCompanion
#12 468.3 2.59MB spring-data-jpa-3.5.1.jar 3.61MB byte[] for reflection metadata
#12 468.3 2.28MB svm.jar (Native Image) 1.71MB java.lang.String[]
#12 468.3 2.17MB jackson-databind-2.19.1.jar 1.68MB java.lang.reflect.Method
#12 468.3 2.06MB postgresql-42.7.7.jar 1.60MB c.o.svm.core.hub.DynamicHub$ReflectionMetadata
#12 468.3 39.77MB for 285 more packages 12.52MB for 8591 more object types
#12 468.3 --
Non working project native build logs:
#12 131.7 For detailed information and explanations on the build output, visit:
#12 131.7 https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
#12 131.7 ------------------------------------------------------------------------------------------------------------------------
#12 138.4 [1/8] Initializing... (15.2s @ 0.40GB)
#12 138.4 Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
#12 138.4 Graal compiler: optimization level: 2, target machine: x86-64-v3
#12 138.4 C compiler: gcc (redhat, x86_64, 11.4.1)
#12 138.4 Garbage collector: Serial GC (max heap size: 80% of RAM)
#12 138.4 4 user-specific feature(s):
#12 138.4 - com.oracle.svm.thirdparty.gson.GsonFeature
#12 138.4 - org.eclipse.angus.activation.nativeimage.AngusActivationFeature
#12 138.4 - org.eclipse.angus.mail.nativeimage.AngusMailFeature
#12 138.4 - org.springframework.aot.nativex.feature.PreComputeFieldFeature
#12 138.4 ------------------------------------------------------------------------------------------------------------------------
#12 138.4 2 experimental option(s) unlocked:
#12 138.4 - '-H:ServiceLoaderFeatureExcludeServices' (origin(s): 'META-INF/native-image/org.springframework/spring-orm/native-image.properties' in 'file:///home/builder/.m2/repository/org/springframework/spring-orm/6.2.8/spring-orm-6.2.8.jar')
#12 138.4 - '-H:+StaticExecutableWithDynamicLibC' (origin(s): command line)
#12 138.4 ------------------------------------------------------------------------------------------------------------------------
#12 138.4 Build resources:
#12 138.4 - 8.35GB of memory (26.8% of 31.12GB system memory, determined at start)
#12 138.4 - 16 thread(s) (100.0% of 16 available processor(s), determined at start)
#12 160.0 SLF4J(W): No SLF4J providers were found.
#12 160.0 SLF4J(W): Defaulting to no-operation (NOP) logger implementation
#12 160.0 SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
#12 295.4 [2/8] Performing analysis... [*****] (156.6s @ 5.14GB)
#12 295.4 48,186 reachable types (91.6% of 52,622 total)
#12 295.5 75,184 reachable fields (64.4% of 116,676 total)
#12 295.6 234,049 reachable methods (61.7% of 379,447 total)
#12 295.6 14,558 types, 3,834 fields, and 21,568 methods registered for reflection
#12 295.6 65 types, 67 fields, and 57 methods registered for JNI access
#12 295.6 4 native libraries: dl, pthread, rt, z
#12 317.6 [3/8] Building universe... (22.0s @ 4.46GB)
#12 329.5 [4/8] Parsing methods... [***] (11.8s @ 4.99GB)
#12 341.7 [5/8] Inlining methods... [****] (10.4s @ 3.53GB)
#12 432.5 [6/8] Compiling methods... [*********] (90.7s @ 4.22GB)
#12 463.5 [7/8] Layouting methods... [*****] (31.0s @ 4.76GB)
#12 490.5 [8/8] Creating image... [*****] (26.6s @ 5.53GB)
#12 490.5 107.61MB (51.89%) for code area: 151,983 compilation units
#12 490.5 99.35MB (47.90%) for image heap: 934,422 objects and 1,275 resources
#12 490.5 442.41kB ( 0.21%) for other data
#12 490.5 207.39MB in total
#12 490.5 ------------------------------------------------------------------------------------------------------------------------
#12 490.5 Top 10 origins of code area: Top 10 object types in image heap:
#12 490.5 16.10MB hibernate-core-6.6.18.Final.jar 32.88MB byte[] for code metadata
#12 490.5 16.00MB java.base 15.14MB byte[] for java.lang.String
#12 490.5 5.56MB jdk.proxy4 11.92MB java.lang.Class
#12 490.5 4.82MB java.desktop 9.24MB java.lang.String
#12 490.5 4.60MB tomcat-embed-core-10.1.42.jar 4.91MB byte[] for embedded resources
#12 490.5 4.12MB java.xml 4.04MB com.oracle.svm.core.hub.DynamicHubCompanion
#12 490.5 2.59MB spring-data-jpa-3.5.1.jar 3.53MB byte[] for reflection metadata
#12 490.5 2.17MB svm.jar (Native Image) 1.86MB java.lang.String[]
#12 490.5 2.15MB jackson-databind-2.19.1.jar 1.69MB c.o.svm.core.hub.DynamicHub$ReflectionMetadata
#12 490.5 2.07MB postgresql-42.7.7.jar 1.32MB java.lang.reflect.Method
#12 490.5 46.33MB for 308 more packages 12.82MB for 8683 more object types
#12 490.5 ------------------------------------------------------------------------------------------------------------------------
As you can see from logs META-INF/native-image/org.springframework/spring-orm/native-image.properties is mentioned during build and it has Args = -H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider. So what causes BytecodeProvider to still be used anyway?
Comment From: sdeleuze
As you can see from logs META-INF/native-image/org.springframework/spring-orm/native-image.properties is mentioned during build and it has Args = -H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider. So what causes BytecodeProvider to still be used anyway?
@ma-hab I don't know, maybe that's a GraalVM bug. I can only reproduce with OP project with tracing agent generated . Is your use case also involving using metadata generated by the GraalVM tracing agent? Can you provide a reproducer that does not involves metadata generated by the tracing agent?
Comment From: sdeleuze
I have asked GraalVM team feedabck on this one to understand what happens.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: sdeleuze
This issue is caused by the \QMETA-INF/services/org.hibernate.bytecode.spi.BytecodeProvider\E entry in the resource-config.json file generated by the tracing agent. It adds the related file resource by default ignored by Spring, so you may want to exclude it from the generated config.
Comment From: HydroCarbon
This issue is caused by the
\QMETA-INF/services/org.hibernate.bytecode.spi.BytecodeProvider\Eentry in theresource-config.jsonfile generated by the tracing agent. It adds the related file resource by default ignored by Spring, so you may want to exclude it from the generated config.
@sdeleuze I think I’ve found the cause. When I use RuntimeHintsRegistrar to register all resources with the pattern **/*, this exception occurs. However, when I use a more precise expression to match specific resources like "key/*.key", the error does not happen. Could it be that this broad pattern causes some resource files to be registered incorrectly, leading to the exception?
Comment From: sdeleuze
Yes, I think so.
Comment From: ma-hab
Yes indeed, that's what I figured out aswell. I think that when you register all resources you also register the META-INF/services/org.hibernate.bytecode.spi.BytecodeProvider from hibernate-core jar. Then hibernate will see BytecodeProvider that is loaded from classpath here and try to use it which will fail with exception OP mentioned. This happens despite the fact that spring-core jar contains native-image.properties with Args = -H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider
Now here's what I think why this happens:
By default graal seems to automatically register all resources from META-INF/services but you can exclude some specific services with ServiceLoaderFeatureExcludeServices which is exactly what spring does. Now the question is how is graalvm supposed to behave when on one hand you explictly exclude service with ServiceLoaderFeatureExcludeServices flag while on other hand you register that seme service as resource like @HydroCarbon mentioned. It seems that graal prioritizes resource registration over ServiceLoaderFeatureExcludeServices which might not be intended behaviour. This seems to be a good question for graalvm team.
Comment From: adrianoavelino
I only add the file src/main/resources/META-INF/native-image/native-image.properties in my project and worked with the content below:
Args = -H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider
Thanks