简体   繁体   English

Spring 引导:数据源属性

[英]Spring Boot: Datasource properties

I have a confusion regarding datasource autoconfiguration in Spring-boot.我对 Spring-boot 中的数据源自动配置感到困惑。 From what I have read, we have to specify the datasource properties in the form spring.datasource.* .根据我的阅读,我们必须以spring.datasource.*的形式指定数据源属性。 But my application code works fine if I supply property name in the form SPRING_DATASOURCE_* .但是,如果我以SPRING_DATASOURCE_*形式提供属性名称,我的应用程序代码就可以正常工作。 Is there any reason that I am missing, due to which it works?有什么理由让我失踪,因为它有效吗? Please clarify.请说清楚。

I think You've come across a feature of spring boot called Relaxed Binding .我认为您已经遇到了 spring 引导的一项功能,称为Relaxed Binding

It allows using some "relaxed" rules for binding to ConfigurationProperties.它允许使用一些“宽松”的规则来绑定到 ConfigurationProperties。 So essentially both ways of definition have the same effect in your application.因此,本质上这两种定义方式在您的应用程序中具有相同的效果。

Here you can find a link to the relevant chapter in the official documentation 在这里你可以找到官方文档中相关章节的链接

Spring Boot has so-called Relaxed Binding https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding which allows you to define configuration in different ways: Spring引导具有所谓的宽松绑定允许您以不同的方式定义配置:

  • acme.my-project.person.first-name acme.myProject.person.firstName acme.my-project.person.first-name acme.myProject.person.firstName
  • acme.myProject.person.firstName acme.myProject.person.firstName
  • acme.my_project.person.first_name acme.my_project.person.first_name
  • ACME_MYPROJECT_PERSON_FIRSTNAME ACME_MYPROJECT_PERSON_FIRSTNAME

The latter is often used when passed via environment variables.后者通常在通过环境变量传递时使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring Boot 中设置 DataSource 的属性 - Set properties for DataSource in Spring boot 使用ConfigurationProperties注释的Spring Boot数据源,但未加载属性 - Spring Boot Datasource annotated with ConfigurationProperties but the properties are not loaded Spring Boot 在运行时更改 DataSource 和 JPA 属性 - Spring Boot change DataSource and JPA properties at runtime Spring Boot spring.datasource.CONFIGURATION_PROPERTIES无法序列化 - Spring Boot spring.datasource.CONFIGURATION_PROPERTIES Cannot Serialize Heroku 是否重写了 Spring Boot 的 spring.datasource.url、spring.datasource.username 和 spring.datasource.password 属性? - Is Heroku rewrites Spring Boot's spring.datasource.url, spring.datasource.username and spring.datasource.password properties? Spring Boot:从另一个属性文件读取数据源属性 - Spring Boot: Read Datasource properties from another property file 使用预定义的数据源属性生成 Spring Boot WAR 文件无法部署 - Generating a Spring Boot WAR file with datasource properties predefined failing to deploy Spring Boot-多个数据源的连接池属性 - Spring boot - connection pool properties for more than one DataSource Spring Boot Multiple Datasource - Spring Boot Multiple Datasource "Spring Boot 中 application.properties 中的 datasource.url 和 datasource.driverClassName 是什么" - What is datasource.url and datasource.driverClassName in application.properties in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM