Hello. There is an application using spring + hibernate. There are two profiles in pom.xml. Here they are:
<profiles> <profile> <id>hsqldb</id> <dependencies> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>2.4.0</version> </dependency> </dependencies> </profile> <profile> <id>mysql</id> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> <version>8.5.15</version> </dependency> </dependencies> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> The application is working fine. The profile used is correct (mysql). But how to specify a profile for tests? If you make a dependency for hsqldb to root dependencies, then the tests work. In the configuration files of the srping, I also divide into profiles. Here is the profile for hsqldb:
<beans profile="hsqldb"> <jdbc:embedded-database id="dataSource" type="HSQL"> <jdbc:script location="classpath:db/hsqldb/initDB.sql"/> <jdbc:script location="classpath:db/hsqldb/populateDB.sql"/> </jdbc:embedded-database> </beans> Actually I run the tests with these settings:
@ContextConfiguration({ "classpath:spring/spring-app.xml", "classpath:spring/spring-db.xml", "classpath:spring/spring-mvc.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles({Profiles.HSQLDB}) @Transactional Actually the error itself, according to which the tests fall:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'databaseType' threw exception; nested exception is java.lang.IllegalStateException: Driver for test database type [HSQL] is not available in the classpath
mvn clean test -P hsqldbnot work? - Sergi