baomidou / dynamic-datasource

dynamic datasource for springboot 多数据源 动态数据源 主从分离 读写分离 分布式事务
https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611
Apache License 2.0
4.76k stars 1.2k forks source link

4.2.0版本在用GraalVM时与HikariCP的兼容问题 #597

Closed tuhe32 closed 1 year ago

tuhe32 commented 1 year ago

Please fill it out carefully, or it will be closed. 请认真填写,不然会直接关闭。

Enviroment

Version info: 'GraalVM 22.3.0 Java 17 CE' Java version info: '17.0.5+8-jvmci-22.3-b08' C compiler: cc (apple, x86_64, 13.1.6)

JDK Version(required): '17.0.5+8-jvmci-22.3-b08' SpringBoot Version(required): 3.1.4 dynamic-datasource-spring-boot-starter Version(required): 4.2.0 druid Version(optional):

Describe what happened

项目用了HikariCP连接池 用mvn -Pnative clean native:compile 打包是成功的。启动报错:

Expected Result:

Actual Result:

If there is an exception,or aop invalid,please attach the exception trace:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.4)

2023-11-27T17:01:08.956+08:00  INFO 88353 --- [           main] c.e.bootnative.BootNativeApplication     : Starting AOT-processed BootNativeApplication using Java 17.0.5 with PID 88353 (/Users/liubin/work/projects/boot-native/target/boot-native started by liubin in /Users/liubin/work/projects/boot-native)
2023-11-27T17:01:08.956+08:00  INFO 88353 --- [           main] c.e.bootnative.BootNativeApplication     : No active profile set, falling back to 1 default profile: "default"
2023-11-27T17:01:08.971+08:00  INFO 88353 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource.dynamic-com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties' of type [com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-11-27T17:01:08.971+08:00  INFO 88353 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAopConfiguration' of type [com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAopConfiguration$$SpringCGLIB$$0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-11-27T17:01:08.972+08:00  WARN 88353 --- [           main] c.b.d.d.support.DataSourceClassResolver  : Failed to init mybatis-plus support.
2023-11-27T17:01:08.972+08:00  INFO 88353 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dsProcessor' of type [com.baomidou.dynamic.datasource.processor.DsJakartaHeaderProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2023-11-27T17:01:09.006+08:00  INFO 88353 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-11-27T17:01:09.007+08:00  INFO 88353 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-11-27T17:01:09.007+08:00  INFO 88353 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.13]
2023-11-27T17:01:09.020+08:00  INFO 88353 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-11-27T17:01:09.020+08:00  INFO 88353 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 64 ms
2023-11-27T17:01:09.034+08:00  WARN 88353 --- [           main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'run': Unsatisfied dependency expressed through method 'run' parameter 0: Error creating bean with name 'bootNativeApplication.MyMapper': Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'
2023-11-27T17:01:09.034+08:00  INFO 88353 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-11-27T17:01:09.035+08:00 ERROR 88353 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'run': Unsatisfied dependency expressed through method 'run' parameter 0: Error creating bean with name 'bootNativeApplication.MyMapper': Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:317) ~[na:na]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArguments(BeanInstanceSupplier.java:260) ~[na:na]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:200) ~[na:na]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[boot-native:6.0.12]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[boot-native:6.0.12]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[boot-native:6.0.12]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[boot-native:3.1.4]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) ~[boot-native:3.1.4]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[boot-native:3.1.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[boot-native:3.1.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[boot-native:3.1.4]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[boot-native:3.1.4]
    at com.example.bootnative.BootNativeApplication.main(BootNativeApplication.java:23) ~[boot-native:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bootNativeApplication.MyMapper': Cannot resolve reference to bean 'sqlSessionTemplate' while setting bean property 'sqlSessionTemplate'
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:377) ~[na:na]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:135) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1682) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1417) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:910) ~[na:na]
    at org.springframework.beans.factory.support.RegisteredBean.resolveAutowiredArgument(RegisteredBean.java:229) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:314) ~[na:na]
    ... 21 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer': Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0: Error creating bean with name 'dataSource': com.zaxxer.hikari.HikariConfig.<init>()
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:317) ~[na:na]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArguments(BeanInstanceSupplier.java:260) ~[na:na]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:200) ~[na:na]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:312) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:365) ~[na:na]
    ... 36 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': com.zaxxer.hikari.HikariConfig.<init>()
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1417) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:910) ~[na:na]
    at org.springframework.beans.factory.support.RegisteredBean.resolveAutowiredArgument(RegisteredBean.java:229) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:314) ~[na:na]
    ... 50 common frames omitted
Caused by: java.lang.NoSuchMethodException: com.zaxxer.hikari.HikariConfig.<init>()
    at java.base@17.0.5/java.lang.Class.getConstructor0(DynamicHub.java:3585) ~[boot-native:na]
    at java.base@17.0.5/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754) ~[boot-native:na]
    at com.baomidou.dynamic.datasource.toolkit.ConfigMergeCreator.create(ConfigMergeCreator.java:53) ~[na:na]
    at com.baomidou.dynamic.datasource.creator.hikaricp.HikariDataSourceCreator.createDataSource(HikariDataSourceCreator.java:75) ~[boot-native:na]
    at com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator.createDataSource(DefaultDataSourceCreator.java:97) ~[boot-native:na]
    at com.baomidou.dynamic.datasource.provider.AbstractDataSourceProvider.createDataSourceMap(AbstractDataSourceProvider.java:53) ~[boot-native:na]
    at com.baomidou.dynamic.datasource.provider.YmlDynamicDataSourceProvider.loadDataSources(YmlDynamicDataSourceProvider.java:53) ~[boot-native:na]
    at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.afterPropertiesSet(DynamicRoutingDataSource.java:231) ~[boot-native:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817) ~[boot-native:6.0.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[boot-native:6.0.12]
    ... 62 common frames omitted
Just paste your stack trace here!

Steps to reproduce

测试用例:

huayanYu commented 1 year ago

mvn -Pnative clean native:compile 跑不起来, 看异常感觉和classLoader有关...先自己排查看下也

linghengqian commented 1 year ago
tuhe32 commented 1 year ago
  • Can you create a git of this zip at github.com so I can verify it via codespaces?
  • Please format your Error Log via markdown, which seems to be missing HikariCP’s GraalVM Reachability Metadata.

测试用例已经放到 git 上。https://github.com/tuhe32/boot-native.git mvn -Pnative clean native:compile 是成功的。 启动项目时报错。

linghengqian commented 1 year ago
linghengqian commented 1 year ago
linghengqian commented 1 year ago
linghengqian commented 1 year ago
huayanYu commented 1 year ago

说实话,我完全不了解GraalVM.... mybatis-plus支持springboot3的相关issue https://github.com/baomidou/mybatis-plus/issues/5527

linghengqian commented 1 year ago
wssy001 commented 1 year ago

@linghengqian 引入 graal-sdk 纯属是无奈之举 正如你前文提及的,Tracing Agent无法收集到lambdaCapturingTypes内容;而且Spring团队也不重视,之前有开发者提了feat,要求适配graal-sdkorg.graalvm.nativeimage.hosted.RuntimeSerialization#registerLambdaCapturingClass这一方法,结果还被当成了无意义提案。

linghengqian commented 1 year ago

@linghengqian 引入 graal-sdk 纯属是无奈之举 正如你前文提及的,Tracing Agent无法收集到lambdaCapturingTypes内容;而且Spring团队也不重视,之前有开发者提了feat,要求适配graal-sdkorg.graalvm.nativeimage.hosted.RuntimeSerialization#registerLambdaCapturingClass这一方法,结果还被当成了无意义提案。

{
  "types":[
  ],
  "lambdaCapturingTypes":[
    {
      "name":"com.example.bootnative.BootNativeApplication"
    }
  ],
  "proxies":[
  ]
}
huayanYu commented 1 year ago

所以和动态数据源无关是吧.

linghengqian commented 1 year ago

所以和动态数据源无关是吧.

huayanYu commented 1 year ago

不明觉厉,closed.

bob266 commented 11 months ago

所以和动态数据源无关是吧.

在你的例子里面,可以跑起来,但是我要如何在编译的时候不报错呢

linghengqian commented 11 months ago

所以和动态数据源无关是吧.

在你的例子里面,可以跑起来,但是我要如何在编译的时候不报错呢