I have a Springboot project and as part of my tests I use embedded Redis server. When I run a specific test class with Intellij it works fine and tests pass. But when I use mvn clean test
command to run tests I receive the following error:
BeanCreationException: Error creating bean with name'core.config.TestRedisConfiguration': Invocation of init methodfailed; nested exception is java.lang.RuntimeException: Can't startredis server. Check logs for details.
This is the dependency in my pom.xml file:
<dependency><groupId>com.github.kstyrc</groupId><artifactId>embedded-redis</artifactId><version>0.6</version><scope>test</scope></dependency>
And this is my TestRedisConfiguration class:
import org.springframework.beans.factory.annotation.Valueimport org.springframework.boot.test.context.TestConfigurationimport redis.embedded.RedisServerimport redis.embedded.RedisServerBuilderimport javax.annotation.PostConstructimport javax.annotation.PreDestroy@TestConfigurationclass TestRedisConfiguration(@Value("\${redis.port:63799}") private val port: Int) { private val redisServer: RedisServer init { redisServer = RedisServerBuilder().port(port).build() } @PostConstruct fun postConstruct() { redisServer.start() } @PreDestroy fun preDestroy() { redisServer.stop() }}