【问题标题】:Property in IntelliJ: driver-class-name or driverClassName?IntelliJ 中的属性:驱动程序类名称或驱动程序类名称?
【发布时间】:2021-05-17 07:16:19
【问题描述】:

我使用 IntelliJ IDEA,IntelliSense 建议在 application.properties 文件中分配 jdbc 驱动程序为

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

在我输入时查看图像

但是the answer,这是错误的。应该是

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

但是与 JetBrains 相关的网站似乎表明使用 driver-class-name 可能是正确的。

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

所以我很困惑。哪一个是对的?是不是 IntelliJ IDEA 的 bug?

【问题讨论】:

    标签: java spring intellij-idea jdbc


    【解决方案1】:

    Spring Boot 支持这两种属性格式,并且它们可以互换用于由属性绑定 (@ConfigurationProperties beans) 定义的属性。

    另见Relaxed BindingSpring Boot Features documentation:

    Spring Boot 使用一些宽松的规则来绑定Environment @ConfigurationProperties beans 的属性,所以不需要 在 Environment 属性名称和 bean 属性名称。这很有用的常见示例包括 破折号分隔的环境属性(例如,context-path 绑定到contextPath)和大写的环境属性(对于 例如,PORT 绑定到 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 Boot工具生成的Spring Boot JAR文件中包含的信息,专门针对spring.datasource.driver-class-name,这个属性名是从META-INF/additional-spring-configuration-metadata.json中获取的spring-boot-autoconfigure JAR 文件。也是Common Application properties中列出的属性。

    您列出的 Youtrack 问题似乎是一个不相关的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      相关资源
      最近更新 更多