Spring Boot仅使用src / test / resources下的application.properties,而不会覆盖src / java / resources下的application.properties

时间:2019-01-16 12:25:39

标签: java hibernate spring-boot jpa h2

我们有用于生产的MYSQL,并且我正在做(很好地尝试)添加h2来测试数据库...。这里有问题。

我在application.properties下添加了src/test/resources

enter image description here

,默认设置通常为src/java/resources

enter image description here

问题是application.properties下的src/java/resources被配置为像这样使用MYSQL的方式:

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.connectionTimeout=1000
spring.datasource.hikari.idleTimeout=60000
spring.datasource.hikari.minimumIdle=2
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.poolName=FmPool
spring.datasource.hikari.connectionTestQuery=SELECT 1

#-- The below three are causing problem to H2 configuration --
spring.datasource.hikari.autoCommit=false
spring.jpa.database-platform=com.intralot.l10.core.jpa.MySqlDialect
spring.jpa.hibernate.ddl-auto=none

h2的application.properties下的src/test/resources如下所示:

# H2 Console
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=admin
spring.datasource.password=password
spring.datasource.driver-class-name=org.h2.Driver
#spring.datasource.hikari.autoCommit=true
#spring.jpa.hibernate.ddl-auto=create-update

# JPA
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

# Flyway
spring.flyway.enabled=false

当我在application.properties下的src/java/resource中发表评论时以下行:

#-- The below three are causing problem to H2 configuration --
spring.datasource.hikari.autoCommit=false
spring.jpa.database-platform=com.intralot.l10.core.jpa.MySqlDialect
spring.jpa.hibernate.ddl-auto=none

H2配置运行良好,但我不知道为什么会这样..

有什么方法可以完全忽略application.properties下的默认src/java/resources,而仅使用application.properties下的src/test/resources吗?

0 个答案:

没有答案