弹簧轮廓可用于此目的。这将是一种特定的方式:
具有特定于环境的属性文件:
application.properties :
spring.profiles.active: dev
application-dev.properties
spring.jpa.database: MYSQLspring.jpa.hibernate.ddl-auto: updatespring.datasource.url: jdbc:mysql://localhost:3306/dbnamespring.datasource.username: usernamespring.datasource.password: password
application-test.properties
spring.jpa.database: HSQL
在中同时具有 MySQL 和 H2 驱动程序
pom.xml,如下所示:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope></dependency><dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>test</scope></dependency>
最后但并非最不重要的一点是,用注释Test类
@ActiveProfiles("test")。


