alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.9k stars 8.57k forks source link

请问下,druid 支持 graalvm 吗 #5633

Closed choubuzhaole closed 4 months ago

choubuzhaole commented 9 months ago

版本

springboot:3.2.0 druid:1.2.8 graalvm-community-jdk-21.0.1_linux-x64_bin

异常信息

使用 mvn -Pnative clean install 编译后启动可执行文件错误 `Failed to bind properties under 'spring.datasource.druid' to java.util.Properties:

Property: spring.datasource.druid.test-on-borrow
Value: "false"
Origin: class path resource [application.yml] - 73:23
Reason: failed to convert java.util.LinkedHashMap<?, ?> to java.util.Properties (caused by java.lang.NoSuchMethodException: java.util.Properties.<init>())

Action: Update your application's configuration `

lizongbo commented 9 months ago

近期来研究下怎么做支持

lizongbo commented 8 months ago

我本地使用graalvm-jdk-21.0.1+12.1进行了简单验证,

1.版本依赖是 druid-spring-boot-3-starter 1.2.21,使用最简单的spring demo运行,发现会报错

    implementation 'com.alibaba:druid:1.2.21'
    implementation 'com.alibaba:druid-spring-boot-3-starter:1.2.21'

报错信息如下:


        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:149) ~[demo-tests.exe:6.1.2]
        ... 69 common frames omitted
Caused by: java.lang.NullPointerException: null
        at com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceWrapper.afterPropertiesSet(DruidDataSourceWrapper.java:40) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1820) ~[demo-tests.exe:6.1.2]

2.使用本地修改代码后构建的druid-spring-boot-3-starter-1.2.21-SNAPSHOT,使用仓库中的druid:1.2.21,验证,出错信息如下:

Caused by: org.springframework.test.context.aot.TestContextAotException: Failed to process test class [com.example.demo.DemoApplicationTests] for AOT
        at org.springframework.test.context.aot.TestContextAotGenerator.processAheadOfTime(TestContextAotGenerator.java:323)
        at org.springframework.test.context.aot.TestContextAotGenerator.lambda$processAheadOfTime$5(TestContextAotGenerator.java:277)
        ... 9 more
Caused by: org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it:
        com.alibaba.druid.stat.JdbcSqlStat
        com.alibaba.druid.pool.DruidPooledConnection

        at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:100)
        at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsC

3.修改编译参数和代码之后,验证成功

    //implementation 'com.alibaba:druid:1.2.21'
implementation files('D:\\githubProjects\\druid\\core\\target\\druid-1.2.21-SNAPSHOT.jar')
    //implementation 'com.alibaba:druid-spring-boot-3-starter:1.2.21'
    implementation files('D:\\githubProjects\\druid\\druid-spring-boot-3-starter\\target\\druid-spring-boot-3-starter-1.2.21-SNAPSHOT.jar')

我提交一下pr支持。

lizongbo commented 8 months ago

我又验证了一下是没有报错的, druid:1.2.8版本应该是太低了,使用 1.2.21版本验证吧

Lin-Van commented 8 months ago

我又验证了一下是没有报错的, druid:1.2.8版本应该是太低了,使用 1.2.21版本验证吧

不能直接 implementation 'com.alibaba:druid-spring-boot-starter:1.2.21' 吗

lizongbo commented 8 months ago

我又验证了一下是没有报错的, druid:1.2.8版本应该是太低了,使用 1.2.21版本验证吧

不能直接 implementation 'com.alibaba:druid-spring-boot-starter:1.2.21' 吗

我是用的springboot3,当然是用druid-spring-boot-3-starter验证。

springboot2的,用druid-spring-boot-starter即可。

choubuzhaole commented 8 months ago

https://github.com/alibaba/druid/issues/5371#issuecomment-1879750732 请问下预计什么时候发布这个版本

lizongbo commented 8 months ago

#5371 (comment) 请问下预计什么时候发布这个版本

预计春节前发布

jiyis commented 7 months ago

#5371 (comment) 请问下预计什么时候发布这个版本

预计春节前发布

请问下发布了吗?我这边用的druid-spring-boot-3-starter:1.2.21版本,出现以下错误Caused by: java.lang.NoSuchMethodException: com.alibaba.druid.pool.DruidDataSource.()

lizongbo commented 4 months ago

1.2.22已经支持