@Slf4j @CompileStatic class GrailsCacheManagerAliasRegistrar extends java.lang.Object implements BeanFactoryPostProcessor
Names the cache manager called grailsCacheManager after the field a cache-aware class has it
injected into, so that Spring takes it where it cannot otherwise choose.
GrailsCacheManagerAware injects a CacheManager by type. Beside a second cache
manager, such as the one the Spring Security plugin defines when cacheUsers is set, Spring
cannot choose by type, and falls back to the bean named like the field. A trait's field is renamed
in the class that implements it, so no bean matched, and the application failed to start. With this
alias the renamed field matches grailsCacheManager. Where Spring could choose, which is the
only cache manager, or one marked primary or with a priority, nothing changes.
Spring takes a bean named like the field before one with a higher priority, so the alias is left
out where another cache manager is marked primary or has a priority, to keep Spring's choice there.
Otherwise a grailsCacheManager created from a cache-aware bean, which Spring gave the other
cache manager, would be asked for while it is being created, and fail. The priority is read from the
class of the bean as its definition declares it, as no bean is created here; a priority that only
the created object has, behind a factory method declared to return a CacheManager, is not
seen.
The alias is registered after every bean definition is in, so a grailsCacheManager that a
cache provider plugin or the application defines gets it too, and it is registered only where there
is a bean of that name and the alias is free.
| Type | Name and description |
|---|---|
static java.lang.String |
ALIASThe name the trait's field has in each class that implements it. |
static java.lang.String |
CACHE_MANAGER_BEAN_NAME |
| Constructor and description |
|---|
GrailsCacheManagerAliasRegistrar() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
The name the trait's field has in each class that implements it.