属性 在 IntelliJ 中:driver-class-name 或 driverClassName?
Property in IntelliJ: driver-class-name or driverClassName?
我使用 IntelliJ IDEA,IntelliSense 建议使用在 application.properties 文件中分配 jdbc 驱动程序作为
spring.datasource.driver-class-name=com.microsoft.jdbc.sqlserver.SQLServerDriver
输入时看到图像
但是,那是错误的。应该是
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
然而,与 JetBrains 相关的网站似乎表明使用 driver-class-name
可能是正确的。
所以我很困惑。哪一个是对的?是IntelliJ IDEA的bug吗?
Spring Boot 支持这两种格式的属性,它们可以互换用于 属性 绑定定义的属性(@ConfigurationProperties
bean)。
另见 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
).
换句话说,假设 spring.datasource.driverClassName
是通过 @ConfigurationProperties
bean 定义的,您可以同时使用 spring.datasource.driver-class-name
和 spring.datasource.driverClassName
。 kebab-case 形式是推荐的形式。宽松的绑定是 - AFAIK - 在 Spring Boot 2 中引入,所以你提到的问题可能仍在 Spring Boot 1.x.
无论如何,IntelliJ 的自动完成在这种情况下不会出错,因为它使用 Spring 引导 JAR 文件中包含的信息,由 Spring 引导工具生成,专门用于 spring.datasource.driver-class-name
,此 属性 名称是从 spring-boot-autoconfigure JAR 文件中的 META-INF/additional-spring-configuration-metadata.json
获得的。也是Common Application properties中列出的属性。
您列出的 Youtrack 问题似乎是一个无关的问题。
我使用 IntelliJ IDEA,IntelliSense 建议使用在 application.properties 文件中分配 jdbc 驱动程序作为
spring.datasource.driver-class-name=com.microsoft.jdbc.sqlserver.SQLServerDriver
输入时看到图像
但是
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
然而,与 JetBrains 相关的网站似乎表明使用 driver-class-name
可能是正确的。
所以我很困惑。哪一个是对的?是IntelliJ IDEA的bug吗?
Spring Boot 支持这两种格式的属性,它们可以互换用于 属性 绑定定义的属性(@ConfigurationProperties
bean)。
另见 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 theEnvironment
property name and the bean property name. Common examples where this is useful include dash-separated environment properties (for example,context-path
binds tocontextPath
), and capitalized environment properties (for example,PORT
binds toport
).
换句话说,假设 spring.datasource.driverClassName
是通过 @ConfigurationProperties
bean 定义的,您可以同时使用 spring.datasource.driver-class-name
和 spring.datasource.driverClassName
。 kebab-case 形式是推荐的形式。宽松的绑定是 - AFAIK - 在 Spring Boot 2 中引入,所以你提到的问题可能仍在 Spring Boot 1.x.
无论如何,IntelliJ 的自动完成在这种情况下不会出错,因为它使用 Spring 引导 JAR 文件中包含的信息,由 Spring 引导工具生成,专门用于 spring.datasource.driver-class-name
,此 属性 名称是从 spring-boot-autoconfigure JAR 文件中的 META-INF/additional-spring-configuration-metadata.json
获得的。也是Common Application properties中列出的属性。
您列出的 Youtrack 问题似乎是一个无关的问题。