【问题标题】:I have created a spring boot application我创建了一个弹簧启动应用程序
【发布时间】:2020-03-19 18:01:29
【问题描述】:

我在 pom.xml 的内存数据库中添加了对 h2 的依赖,但我没有在 application.properties 中配置 h2 数据库属性,但我的 jpa 类仍在 h2 数据库中创建,有人能告诉我怎么可能吗?

【问题讨论】:

    标签: spring-data-jpa h2


    【解决方案1】:

    这是由于spring boot的自动配置功能

    https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/html/using-boot-auto-configuration.html

    Spring Boot 自动配置尝试根据您添加的 jar 依赖项自动配置您的 Spring 应用程序。例如,如果 HSQLDB 在你的类路径上,并且你没有手动配置任何数据库连接 bean,那么 Spring Boot 会自动配置一个内存数据库。

    您需要通过将@EnableAutoConfiguration 或@SpringBootApplication 注释添加到您的@Configuration 类之一来选择加入自动配置。

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 1970-01-01
      • 2022-07-21
      • 2018-12-26
      • 1970-01-01
      • 2017-02-12
      • 2021-04-13
      • 1970-01-01
      • 2017-12-28
      相关资源
      最近更新 更多