【发布时间】:2019-02-14 06:28:19
【问题描述】:
我正在使用 Spring Boot 2.0.4.RELEASE,并将src/test/resources/application.yml 配置为
spring:
jpa:
show-sql: false
hibernate:
dialect: org.hibernate.dialect.SQLServer2012Dialect
ddl-auto: none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
generate_statistics: false
show_sql: false
我有一个非常简单的测试:
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ExtendWith(SpringExtension.class)
public class MyTest {
...
}
测试忽略了属性(在打印休眠语句时可以很容易地看到)。将相同的属性放在application.properties 文件中是有效的。
将名称更改为 application-test.yml 并在配置文件测试中运行也无济于事。
将@DataJpaTest 注释更改为@SpringBootTest 时,它正在工作...
请务必注意,其余属性(具体与我的应用程序相关且不带 spring.* 前缀的内容正在正常读取和使用
我更喜欢使用 yaml 文件(例如在 /src/main/resources 中),而不是只为纯 JPA 测试加载完整的 @SpringBootTest...还有什么我可以配置的吗?
【问题讨论】:
-
对我来说它打印 jpa sql 语句而不读取标志,超级烦人!
-
尝试添加:@TestPropertySource(locations = "classpath:application.yaml")
标签: java spring hibernate spring-boot spring-data-jpa