springboot-how to solve IllegalArgumentException: Host must not be empty when using spring boot data redis and lettuce?

1. Purpose

In this post, I would demo how to solve the below exception or error when using spring boot data redis and lettuce:



  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-03-21 15:27:30.705  INFO 61218 --- [    Test worker] c.bswen.app10.service.TestRedisService   : Starting TestRedisService using Java 1.8.0_121 on MBP-bswen with PID 61218 (started by bswen in /Users/bswen/private/bw/bswen-github/bswen-springboot23/app10)
2021-03-21 15:27:30.706  INFO 61218 --- [    Test worker] c.bswen.app10.service.TestRedisService   : The following profiles are active: test
2021-03-21 15:27:31.572  INFO 61218 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-03-21 15:27:31.576  INFO 61218 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-03-21 15:27:31.599  INFO 61218 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 Redis repository interfaces.
2021-03-21 15:27:32.011  WARN 61218 --- [    Test worker] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisService': Unsatisfied dependency expressed through field 'redisClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClient' defined in class path resource [com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
2021-03-21 15:27:32.035  INFO 61218 --- [    Test worker] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-21 15:27:32.088 ERROR 61218 --- [    Test worker] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisService': Unsatisfied dependency expressed through field 'redisClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClient' defined in class path resource [com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
    ...
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_121]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClient' defined in class path resource [com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
....   org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56) ~[na:na]
    at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_121]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisService': Unsatisfied dependency expressed through field 'redisClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClient' defined in class path resource [com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.3.3.jar:5.3.3]
   org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.3.jar:5.3.3]
    ... 122 common frames omitted
Caused by: java.lang.IllegalArgumentException: Host must not be empty
    at io.lettuce.core.internal.LettuceAssert.notEmpty(LettuceAssert.java:44) ~[lettuce-core-6.0.2.RELEASE.jar:6.0.2.RELEASE]
    at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1151) ~[lettuce-core-6.0.2.RELEASE.jar:6.0.2.RELEASE]
    at com.bswen.app10.config.RedisConfiguration.redisClient(RedisConfiguration.java:17) ~[main/:na]
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a.CGLIB$redisClient$0(<generated>) ~[main/:na]
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a$$FastClassBySpringCGLIB$$5b3d5194.invoke(<generated>) ~[main/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.3.jar:5.3.3]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.3.jar:5.3.3]
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a.redisClient(<generated>) ~[main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.3.jar:5.3.3]
    ... 123 common frames omitted


Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:355)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$7(ClassBasedTestDescriptor.java:350)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
    at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
    at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:349)
 org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
...   org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    ... 90 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisClient' defined in class path resource [com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
    ... 122 more
Caused by: java.lang.IllegalArgumentException: Host must not be empty
    at io.lettuce.core.internal.LettuceAssert.notEmpty(LettuceAssert.java:44)
    at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1151)
    at com.bswen.app10.config.RedisConfiguration.redisClient(RedisConfiguration.java:17)
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a.CGLIB$redisClient$0(<generated>)
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a$$FastClassBySpringCGLIB$$5b3d5194.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at com.bswen.app10.config.RedisConfiguration$$EnhancerBySpringCGLIB$$fd54fa1a.redisClient(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 123 more

TestRedisService > testGetAndSet() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:643
            Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:658
                Caused by: org.springframework.beans.BeanInstantiationException at SimpleInstantiationStrategy.java:185
                    Caused by: java.lang.IllegalArgumentException at LettuceAssert.java:44
1 test completed, 1 failed
> Task :app10:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app10:test'.
> There were failing tests. See the results at: file:///Users/bswen/private/bw/bswen-github/bswen-springboot23/app10/build/test-results/test/
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
6 actionable tasks: 5 executed, 1 up-to-date

The core exception is :

[com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
    ... 122 more
Caused by: java.lang.IllegalArgumentException: Host must not be empty
    at io.lettuce.core.internal.LettuceAssert.notEmpty(LettuceAssert.java:44)
    at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1151)
    at com.bswen.app10.config.RedisConfiguration.redisClient(RedisConfiguration.java:17)
    at 

2. The Environment

  • Jdk 8
  • Spring boot 2.4
  • Gradle 6.x

3. The code and solution

3.1 The project structure

The project’s main package is com.bswen.app10, its main purpose is to connect to a redis server and do some unit tests.

└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── bswen
    │   │           └── app10
    │   │               ├── RedisApplication.java
    │   │               ├── config
    │   │               │   └── RedisConfiguration.java
    │   │               ├── domain
    │   │               │   └── SyncCommandCallback.java
    │   │               └── service
    │   │                   └── RedisService.java
    │   └── resources
    │       ├── application-dev.properties
    │       └── application.properties
    └── test
        ├── java
        │   └── com
        │       └── bswen
        │           └── app10
        │               ├── package-info.java
        │               └── service
        │                   └── TestRedisService.java
        └── resources
            └── application-test.properties

3.2 The project’s dependency

Let’s see the project’s gradle dependencies:

plugins {
    id 'org.springframework.boot' version '2.4.2' 
    id 'io.spring.dependency-management' version '1.0.11.RELEASE' 
    id 'java'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation('org.springframework.boot:spring-boot-starter-data-redis')
    implementation 'io.lettuce:lettuce-core'
    implementation 'org.apache.commons:commons-pool2'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        // exclude vintage, because we only use junit5
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    // specify the test profile , spring boot would try to load application-test.properties when testing
    systemProperty 'spring.profiles.active', 'test'
    useJUnitPlatform()
    reports {
        junitXml.enabled = true
        html.enabled = false
    }
}

You can see that we are using spring boot v2.4.2, and we are using spring-boot-starter-redis with lettuce, which is the default connector. we added lettuce-core as redis connection manager.

3.3 The configuration class

We need a configuration class to configure the redis connection.

package com.bswen.app10.config;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("spring.redis")
public class RedisConfiguration {
    private String host;
    private int port;

    @Bean
    RedisClient redisClient() {
        RedisURI uri = RedisURI.Builder.redis(this.host, this.port)
                .build();
        return RedisClient.create(uri);
    }
}

In the above code, we define two fields(host and post) to construct the redisURI , which would be used by Lettuce RedisClient to create the redis connection.

3.4 The configuration file

We have specified the test profile when doing unit testing. So, the src/test/resources/application-test.properties file’s content is as follows:

src/test/resources/application-test.properties:

spring.redis.host=2.3.4.7
spring.redis.port=6379

3.5 The test class

This is the test code:

package com.bswen.app10.service;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class TestRedisService {
    @Autowired
    private RedisService redisService;

    @Test
    public void testGetAndSet() {
        redisService.set("hello","world");
        Assertions.assertEquals(redisService.get("hello"),"world");
    }
}

We just put a key/value to redis and then get the value with the same key, the assertion should be true.

3.6 Run the code

When we run the above test with gradle, we get this exception:

[com/bswen/app10/config/RedisConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.lettuce.core.RedisClient]: Factory method 'redisClient' threw exception; nested exception is java.lang.IllegalArgumentException: Host must not be empty
    ... 122 more
Caused by: java.lang.IllegalArgumentException: Host must not be empty
    at io.lettuce.core.internal.LettuceAssert.notEmpty(LettuceAssert.java:44)
    at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1151)

why?

3.7 The reason

The reason for this error is as follows:

  • The lettuce RedisURI$Builder can not find the host of the redis
  • The host is configured in our RedisConfiguration, but the host field does not have getter and setter to access it

3.8 The solution

So the solution is easy, just add getter/setter to our RedisConfiguration class, just as follows:

package com.bswen.app10.config;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties("spring.redis")
public class RedisConfiguration {
    private String host;
    private int port;

    @Bean
    RedisClient redisClient() {
        RedisURI uri = RedisURI.Builder.redis(this.host, this.port)
                .build();
        return RedisClient.create(uri);
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }
}

3.9 Re-run the test

Testing started at 15:31 ...
> Task :app10:cleanTest
> Task :app10:compileJava
> Task :app10:processResources UP-TO-DATE
> Task :app10:classes
> Task :app10:compileTestJava UP-TO-DATE
> Task :app10:processTestResources UP-TO-DATE
> Task :app10:testClasses UP-TO-DATE
> Task :app10:test
15:31:08.196 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
15:31:08.216 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
15:31:08.264 [Test worker] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.bswen.app10.service.TestRedisService] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
15:31:08.280 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.bswen.app10.service.TestRedisService], using SpringBootContextLoader
15:31:08.285 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.bswen.app10.service.TestRedisService]: class path resource [com/bswen/app10/service/TestRedisService-context.xml] does not exist
15:31:08.285 [Test worker] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.bswen.app10.service.TestRedisService]: class path resource [com/bswen/app10/service/TestRedisServiceContext.groovy] does not exist
15:31:08.286 [Test worker] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.bswen.app10.service.TestRedisService]: no resource found for suffixes {-context.xml, Context.groovy}.
15:31:08.287 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.bswen.app10.service.TestRedisService]: TestRedisService does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
15:31:08.349 [Test worker] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.bswen.app10.service.TestRedisService]
15:31:08.438 [Test worker] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/Users/bswen/private/bw/bswen-github/bswen-springboot23/app10/build/classes/java/main/com/bswen/app10/RedisApplication.class]
15:31:08.439 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.bswen.app10.RedisApplication for test class com.bswen.app10.service.TestRedisService
15:31:08.577 [Test worker] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.bswen.app10.service.TestRedisService]: using defaults.
15:31:08.578 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
15:31:08.603 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]55b822bf, org.springframework.test[email protected]78d3e486, org.springfram[email protected]13d65ec5, org.spri[email protected]3f6f6222, org.springframework.boot.test.a[email protected]2b5602aa, org.springfra[email protected]4c462492, org.springframew[email protected]6d476ba9, org.sp[email protected]29fd7a51, org.springfr[email protected]32256e96, org.springframework[email protected]4fbaaef4, org.springframework.boot.test.autoconfi[email protected]19769e89, org.springframework.boot.test.autoconfi[email protected]5b9b5004, org.springframework.boo[email protected]4253d43f, org.springframework.boot.test.autoconfigu[email protected]58040f8f, org.springf[email protected]75ab50d0]
15:31:08.607 [Test worker] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [[email protected] testClass = TestRedisService, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = TestRedisService, locations = '{}', classes = '{class com.bswen.app10.RedisApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@1355ba10, org.springframework.boot[email protected]0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@2e7d7325, org.springframewor[email protected]96, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@ce7e970, org.[email protected]0, org.springf[email protected]25135e5, [email protected], org[email protected]32d0dfaf], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
15:31:08.641 [Test worker] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-03-21 15:31:08.996  INFO 61274 --- [    Test worker] c.bswen.app10.service.TestRedisService   : Starting TestRedisService using Java 1.8.0_121 on MBP-bswen with PID 61274 (started by bswen in /Users/bswen/private/bw/bswen-github/bswen-springboot23/app10)
2021-03-21 15:31:08.997  INFO 61274 --- [    Test worker] c.bswen.app10.service.TestRedisService   : The following profiles are active: test
2021-03-21 15:31:09.953  INFO 61274 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-03-21 15:31:09.957  INFO 61274 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-03-21 15:31:09.985  INFO 61274 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9 ms. Found 0 Redis repository interfaces.
2021-03-21 15:31:12.034  INFO 61274 --- [    Test worker] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-21 15:31:13.388  INFO 61274 --- [    Test worker] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-03-21 15:31:13.451  INFO 61274 --- [    Test worker] c.bswen.app10.service.TestRedisService   : Started TestRedisService in 4.8 seconds (JVM running for 6.238)
2021-03-21 15:31:13.823  INFO 61274 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
BUILD SUCCESSFUL in 8s
6 actionable tasks: 3 executed, 3 up-to-date
15:31:13: Tasks execution finished ':app10:cleanTest :app10:test --tests "com.bswen.app10.service.TestRedisService"'.

It works!

5. Summary

In this post, we demonstrated how to solve the IllegalArgumentException: Host must not be empty problem when using lettuce with springboot data redis, you can see that we should provide appropriate configurations to lettuce to construct the connection from lettuce to redis server. Thanks for your reading. Regards.

-->