Spring启动不会从yml文件中读取数据库配置

时间:2017-05-14 11:58:29

标签: java database spring-boot

我有这个配置文件:

liquibase:
  enabled: true
  change-log: classpath:/db/changelog/db.changelog-master.yml
management:
  security:
      enabled: false
server:
  port: 8080
spring:
  datasource:
    driverClassName: org.h2.Driver
    url: jdbc:h2:file:./target/h2db/db/develop;DB_CLOSE_DELAY=-1
    username: sa
    password:
  h2:
    console:
        enabled: true

当我尝试检查datasorce时,它连接到" jdbc:h2:mem:testdb"无论如何:

@Component
public class AfterInit implements CommandLineRunner {

    @Autowired
    DataSource dataSource;

    @Override
    public void run(String... args) throws Exception {
        out.println(dataSource);
    }
}

为什么spring boot无法找到合适的数据库配置?

1 个答案:

答案 0 :(得分:0)

当我将依赖关系从runtime("com.h2database:h2")更改为compile("com.h2database:h2")时,Datasource开始工作。 谁能解释一下发生了什么事?