我在 Spring 中做一些测试,我看到了一个奇怪的事情。
当我application.properties像这样设置数据源时
spring.datasource.url = jdbc:mysql://localhost:3306/test?useSSL=false
spring.datasource.username = root
spring.datasource.password = 123456
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Run Code Online (Sandbox Code Playgroud)
并@DataJpaTest用于设置 H2 数据库进行测试,spring 使用 mysql 方言而不是 H2 方言。
这是控制台的一些行
2018-08-22 14:42:53.881 INFO 852 --- [ main] beddedDataSourceBeanFactoryPostProcessor : Replacing 'dataSource' DataSource bean with embedded version
2018-08-22 14:42:53.882 INFO 852 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); …Run Code Online (Sandbox Code Playgroud)