I'm new to Jhipster and started to look at it yesterday. It's one thing I don't know how it is working at the moment so I hope I get the answer here.
Jhipster creates a UserService
which is the service class for managing users. It has a dependency to a CacheManager
which is autowired in the constructor. My IDE is complaining about a missing Bean for the CacheManager
but I thought it was the Bean in the CacheConfuguration
class that handled that dependency
@Configuration
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class })
@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })
public class CacheConfiguration {
private final javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration;
public CacheConfiguration(JHipsterProperties jHipsterProperties) {
JHipsterProperties.Cache.Ehcache ehcache =
jHipsterProperties.getCache().getEhcache();
jcacheConfiguration = Eh107Configuration.fromEhcacheCacheConfiguration(
CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
ResourcePoolsBuilder.heap(ehcache.getMaxEntries()))
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(ehcache.getTimeToLiveSeconds(), TimeUnit.SECONDS)))
.build());
}
@Bean
public JCacheManagerCustomizer cacheManagerCustomizer() {
return cm -> {
cm.createCache("users", jcacheConfiguration);
cm.createCache(com.mycompany.myapp.domain.User.class.getName(), jcacheConfiguration);
cm.createCache(com.mycompany.myapp.domain.Authority.class.getName(), jcacheConfiguration);
cm.createCache(com.mycompany.myapp.domain.User.class.getName() + ".authorities", jcacheConfiguration);
// jhipster-needle-ehcache-add-entry
};
}
}
Can someone explain how the CacheManager
in UserService
is autowired please.