drtrang / druid-spring-boot

Spring Boot Starter for Druid.
Apache License 2.0
313 stars 85 forks source link

遭遇Canonical names should be kebab-case ('-' separated) #17

Open starlight36 opened 4 years ago

starlight36 commented 4 years ago

Hi~

我在Spring Boot 2.1下使用这个组件时遇到个问题:

***************************
APPLICATION FAILED TO START
***************************

Description:

Configuration property name 'spring.datasource.druid.data-sources.commonMaster' is not valid:

    Invalid characters: 'M'
    Bean: additionConfigController
    Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter

Action:

Modify 'spring.datasource.druid.data-sources.commonMaster' so that it conforms to the canonical names requirements.

提示属性名格式不正确。确认了一下yml里面写的,的确是小写中横线格式的:

spring:
  datasource:
    druid:
      data-sources:
         common-master:
...

跟了一下,是初始化数据源对象时候,bind属性操作使用的beanName拼接,而非最初配置使用的key:

https://github.com/drtrang/druid-spring-boot/blob/885f61ea3e6c62ec2b7d3ac993602a5b3922594d/druid-spring-boot/druid-spring-boot-autoconfigure/src/main/java/com/github/trang/druid/autoconfigure/DruidDataSourceConfiguration.java#L142

所以这里要么想办法把先前的key传过来,要么再做一次驼峰转小写中横线😂