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 badges1 Answer
Reset to default 1Yes, 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.