繁体   English   中英

Spring Boot Test 尝试连接数据库

[英]Spring boot Test tries to connect to Database

我正在尝试为项目运行测试用例并遇到以下问题:运行测试类时,它尝试连接到数据库并失败,并出现以下错误。

java.lang.IllegalStateException: Failed to load ApplicationContext
    at 
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cache': Unsatisfied dependency expressed through field 'migrationPatternService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'migrationPatternService' defined in file [C:\Projects\cloud_genie\cloud-genie-microservice\target\classes\com\virtusa\gto\cloudgenie\service\MigrationPatternService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commonDAO': Unsatisfied dependency expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is liquibase.exception.DatabaseException: java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=23.236.55.227)(port=3306)(type=master) : Socket fail to connect to host:23.236.55.227, port:3306. Connection timed out: connect
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)

这很可能是因为您为 Spring boot application.properties / -.yml 文件提供了 liquibase 或 datasource 属性。

您应该在测试类中覆盖这些属性。 例如,使用像 H2 这样的内存数据库。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM