最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - Springboot : HikariCP Configuration: camelCase vs kebab-case - Stack Overflow

programmeradmin1浏览0评论

I understand this question might seem a bit boring or uninteresting, but I need clarity on the following:

  • which one is recommeneded
  • which one will work (will both work)

Example of HikariCP Configuration in

Configuration in application.yml (kebab-case):

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: myuser
    password: mypassword
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      minimum-idle: 5
      maximum-pool-size: 10
      idle-timeout: 30000
      pool-name: MyHikariPool
      connection-timeout: 20000
      max-lifetime: 1800000

Configuration in application.yml (camelCase):

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: myuser
    password: mypassword
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      minimumIdle: 5
      maximumPoolSize: 10
      idleTimeout: 30000
      poolName: MyHikariPool
      connectionTimeout: 20000
      maxLifetime: 1800000

From my research, it appears that both formats will work due to Spring Boot's relaxed binding rules. However, I want to confirm if this understanding is correct and whether there’s a preferred convention to follow

I understand this question might seem a bit boring or uninteresting, but I need clarity on the following:

  • which one is recommeneded
  • which one will work (will both work)

Example of HikariCP Configuration in

Configuration in application.yml (kebab-case):

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: myuser
    password: mypassword
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      minimum-idle: 5
      maximum-pool-size: 10
      idle-timeout: 30000
      pool-name: MyHikariPool
      connection-timeout: 20000
      max-lifetime: 1800000

Configuration in application.yml (camelCase):

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: myuser
    password: mypassword
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      minimumIdle: 5
      maximumPoolSize: 10
      idleTimeout: 30000
      poolName: MyHikariPool
      connectionTimeout: 20000
      maxLifetime: 1800000

From my research, it appears that both formats will work due to Spring Boot's relaxed binding rules. However, I want to confirm if this understanding is correct and whether there’s a preferred convention to follow

Share Improve this question asked Jan 19 at 5:50 Sudhanshu GuptaSudhanshu Gupta 2,3153 gold badges40 silver badges79 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, your understanding is correct. Spring's relaxed binding rules allow the use of camelCase, kebab-case, and snake_case. However, the recommended convention is to use kebab-case.

One possible reason is that the prefix specified in @ConfigurationProperties should be written in kebab-case, for example:

@ConfigurationProperties(prefix = "my.main-project.person")

Additionally, kebab-case is more natural and readable in YAML, and it's the convention used in Spring Boot's own property naming, as shown in the official documentation.

发布评论

评论列表(0)

  1. 暂无评论