[DATAREDIS-1049] Exception raised when use empty string with keyspaceNotificationsConfigParameter with @EnableRedisRepositories annotation Created: 17/Oct/19  Updated: 18/Nov/19  Resolved: 30/Oct/19

Status: Closed
Project: Spring Data Redis
Component/s: Core
Affects Version/s: 2.2 GA (Moore)
Fix Version/s: 2.2.1 (Moore SR1), 2.3 M1 (Neumann)

Type: Bug Priority: Critical
Reporter: x-wing Assignee: Christoph Strobl
Resolution: Fixed Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File exception.txt    
Last updater: Mark Paluch
Pull Request URL: https://github.com/spring-projects/spring-data-redis/pull/491
Sprint: Moore SR1

 Description   

Running Spring-boot with redis instance on AWS with the following setup will be fine with spring-boot version 2.1.9 but it is now broken with 2.2.0 with an exception shown at the end of this message.

@EnableRedisRepositories(basePackages="com.xyz", redisTemplateRef="redisOperations", enableKeyspaceEvents=RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP, keyspaceNotificationsConfigParameter="")
public class CacheConfiguration extends CachingConfigurerSupport { .. }

[exception.txt](https://github.com/spring-projects/spring-boot/files/3740673/exception.txt)

Further debugging shows that the exception comes from the call made to getRequiredAttribute for keyspaceNotificationsConfigParameter in RedisRepositoryConfigurationExtension

private static AbstractBeanDefinition createRedisKeyValueAdapter(RepositoryConfigurationSource configuration) { 
  return BeanDefinitionBuilder.rootBeanDefinition(RedisKeyValueAdapter.class)
     .addConstructorArgReference((String)configuration.getRequiredAttribute(“redisTemplateRef”, String.class))
    .addConstructorArgReference(“redisConverter”)
    .addPropertyValue(“enableKeyspaceEvents”, configuration.getRequiredAttribute(“enableKeyspaceEvents”, EnableKeyspaceEvents.class))
    .addPropertyValue(“keyspaceNotificationsConfigParameter”, configuration.getRequiredAttribute(“keyspaceNotificationsConfigParameter”, String.class))
    .getBeanDefinition(); }
interface RepositoryConfigurationSource {
  default <T> T getRequiredAttribute(String name, Class<T> type) {
    Assert.hasText(name, “Attribute name must not be null or empty!“);
    return this.getAttribute(name, type).orElseThrow(() -> { 
      return new IllegalArgumentException(String.format(“No attribute named %s found!“, name)); 
      });
   }
}

By comparing Spring Data Commons version 2.2.0 which is used by the latest spring boot releases to the Spring Data Commons 2.1.11 used by the previous release
redisKeyValueAdapterProps.add("keyspaceNotificationsConfigParameter", attributes.getString("keyspaceNotificationsConfigParameter"));.
Definitely this is a change making this field as required and empty string is treated as null which causes the exception here.

Here is the documentation regarding the usage of empty string for this field:
https://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/repository/configuration/EnableRedisRepositories.html#keyspaceNotificationsConfigParameter--

Please recommend a work around or help fix this issue if this is an unintended side effect.

The reason that this empty string is required for AWS is a known subject that AWS does not allow modification of the CONFIG from application so we have to use the server configuration as we have setup with.

 



 Comments   
Comment by x-wing [ 17/Oct/19 ]

This issue was originally raised to spring boot under: https://github.com/spring-projects/spring-boot/issues/18640.

 

Comment by Mark Paluch [ 30/Oct/19 ]

I updated the affected version. It was Lovelace but the description says Spring Data Redis 2.2 which is Moore.

Generated at Mon Jan 27 06:15:09 UTC 2020 using Jira 7.13.8#713008-sha1:1606a5c1e7006e1ab135aac81f7a9566b2dbc3a6.