apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.17k stars 10.21k forks source link

No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>] #2751

Closed chenhuwo closed 4 years ago

chenhuwo commented 5 years ago
Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:

    Property: spring.datasource.type
    Value: com.alibaba.druid.pool.DruidDataSource
    Origin: "spring.datasource.type" from property source "ApolloBootstrapPropertySources"
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]

DataSourceProperrties的type属性是Class类型,springboot中可以转换成Class,此处该如何转换,或者我重新写个配置也可以。

chenhuwo commented 4 years ago

配置中心的配置 spring.datasource.type=druid 这个配置对应的Class

@ConfigurationProperties(prefix = "spring.datasource")
public class DataSourceProperties implements BeanClassLoaderAware, InitializingBean {
      //其他省略
   private Class<? extends DataSource> type;
}

启动的时候会出现上述的错误

Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:

    Property: spring.datasource.type
    Value: com.alibaba.druid.pool.DruidDataSource
    Origin: "spring.datasource.type" from property source "ApolloBootstrapPropertySources"
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]
nobodyiam commented 4 years ago

这个和apollo没啥关系,google参考一下吧

https://www.imooc.com/qadetail/297768

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in 14 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had activity in the last 14 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.