在 Spring Boot 上,h2 的默认数据源 url 来自哪里? [英] Where does the default datasource url for h2 come from on Spring Boot?

查看:79
本文介绍了在 Spring Boot 上,h2 的默认数据源 url 来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了一个新的 spring-boot 1.5.3 项目.添加了一些初学者:

I started a new spring-boot 1.5.3 project. Added some starters:

  • 数据-jpa
  • 入门网站
  • 数据休息

然后添加

  • 开发工具
  • h2

我可以看到数据源自动设置为jdbc:h2:mem:testdb.一切正常,但出于好奇,我试图确定 jdbc:h2:mem:testdb 值的来源.我搜索了 spring-boot、spring-data、spring jdbc 和 devtools 项目的源代码,但我无法找到.据我所知,该值也不是来自 h2 的默认建议.

I can see the datasource is automatically set to jdbc:h2:mem:testdb. Everything is working fine but just out of curiosity I tried to determine from where the jdbc:h2:mem:testdb value comes from. I searched spring-boot, spring-data, spring jdbc and devtools projects' source code but I was unable to find out. As far as I can tell, the value does not come as default suggestion from h2 either.

那么这个值究竟从何而来?

So where does this value exactly come from?

推荐答案

这将来自这个类,它也包含其他类型的 in-mem DB 的默认值.

That would be coming from this class, which also contains the defaults for other flavours of in-mem DBs.

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/EmbeddedDatabaseConnection.java

H2(EmbeddedDatabaseType.H2, "org.h2.Driver", "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"),

如果满足条件,则通过 DataSourceAutoConfiguration 加载,

Which get's loaded via, the DataSourceAutoConfiguration if it meets the criteria,

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java

数据库名称的默认值 testdb 来自 Datasourceproperties 中的默认设置,

The default for the database name, testdb, comes from a default set in the Datasourceproperties,

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java

private String name = "testdb";

这篇关于在 Spring Boot 上,h2 的默认数据源 url 来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆