1

I use IntelliJ IDEA, the IntelliSense suggests the usage of assigning jdbc driver in application.properties file as

spring.datasource.driver-class-name=com.microsoft.jdbc.sqlserver.SQLServerDriver

See the image when I typing

driver

But by the answer, that is wrong. It should be

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver

However a web site related to JetBrains seems indicate that using driver-class-name might be correct.

https://youtrack.jetbrains.com/issue/IDEA-202820?_ga=2.207495315.1822682194.1613252382-718343134.1609267918

So I am confused. Which one is right? Is it a bug of IntelliJ IDEA?

Hello
  • 796
  • 8
  • 30

1 Answers1

2

Spring Boot supports both formats for properties, and they can be used interchangeably for properties defined by property binding (@ConfigurationProperties beans).

See also Relaxed Binding in the Spring Boot Features documentation:

Spring Boot uses some relaxed rules for binding Environment properties to @ConfigurationProperties beans, so there does not need to be an exact match between the Environment property name and the bean property name. Common examples where this is useful include dash-separated environment properties (for example, context-path binds to contextPath), and capitalized environment properties (for example, PORT binds to port).

In other words, given spring.datasource.driverClassName is defined through a @ConfigurationProperties bean, you can use both spring.datasource.driver-class-name and spring.datasource.driverClassName. The kebab-case form is the recommended form. The relaxed binding was - AFAIK - introduced in Spring Boot 2, so maybe the question you referenced was still at Spring Boot 1.x.

In any case, IntelliJ's autocomplete cannot be wrong in this case, because it uses information contained in the Spring Boot JAR files, generated by Spring Boot tools, specifically for spring.datasource.driver-class-name, this property name is obtained from META-INF/additional-spring-configuration-metadata.json in the spring-boot-autoconfigure JAR file. It is also the property listed in Common Application properties.

The Youtrack issue you listed seems to be an unrelated problem.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197