spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Overriding of redisCustomConversions is restricted [DATAREDIS-820]

Open spring-projects-issues opened this issue 7 years ago • 3 comments

James Green opened DATAREDIS-820 and commented

This is one of those "it was working last week I swear" issues.

We are storing a JSON formatted value in a hash and so need to override redisCustomConversions to add the plumbing. In a previous iteration we had two classes:

  1. RedisConfiguration. We added @Configuration and @EnableRedisRepositories. Otherwise this class was empty.
  2. SubscriptionsConfiguration. We added @Configuration and a method annotated @Bean that produced a CustomConversions instance named redisCustomConversions.

Last Friday we noticed in local testing the results of the query were now blank. The logs indicated that the redisCustomConversions were ignored because there was already a bean with that name. I was unable to fix with @Order or @Priority.

As part of our stab-it-until-it-works-again measures we eventually moved the redisCustomConversations method into the RedisConfiguation class, and the local tests burst back to life.

So either there was something nasty on my dev workstation or there's a restriction requiring that bean to be declared within the class annotated @EnableRedisRepositories which I don't see documented. Either way some advice on whether this should be worked on as a bug / clarified in the docs, or "user error" would be good to see to wrap it up


Affects: 1.8.11 (Ingalls SR11)

spring-projects-issues avatar May 01 '18 07:05 spring-projects-issues

Mark Paluch commented

You're seeing an effect how Spring Framework works with @Configuration classes.

Spring Data Redis applies defaulting through RedisRepositoriesRegistrar and RedisRepositoryConfigurationExtension by checking whether there are bean definitions registered for particular names. Configuration classes are processed entirely meaning all imports and @Bean definitions are processed before the next configuration class is introspected for bean declarations. At the time where your class with @EnableRedisRepositories is processed, your CustomConversions isn't visible yet to the bean factory and thus @EnableRedisRepositories registers its default bean.

That said, it looks like the order of which classes were found changed. Adding @Order to your @Configuration classes allows you to reorder config class priority. Alternatively, add @Import(…) to your @EnableRedisRepositories config class.

 

spring-projects-issues avatar May 02 '18 08:05 spring-projects-issues

James Green commented

Mark,

I appreciate your time on this so soon. What you suggest fits with what we saw. The ordering of events at boot did appear to change despite us not being aware of a spring framework version bump being applied locally.

Irrespective, I would settle for this detail to be included in the documentation, just to prevent others from wasting their time as I did

spring-projects-issues avatar May 02 '18 09:05 spring-projects-issues

Mark Paluch commented

Looking at other Spring Framework components (like @EnableScheduling), these components allow for components that are configured outside of the actual configuration class. Let's keep this one open to see whether we can improve beyond documentation

spring-projects-issues avatar May 02 '18 09:05 spring-projects-issues