2

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.

  • It's auto configured by Spring Boot, please check their docs – Gaël Marziou Apr 24 '18 at 09:06
  • I have read the cache part of the spring-boot docs. It says: Use the `spring-boot-starter-cache` “Starter” to quickly add basic caching dependencies. I interpret it as the `CacheManager` is auto-configured by Spring Boot if you have this dependency in your pom. But I cannot find the `spring-boot-starter-cache` in the default Jhipster pom. How does Jhipster satisfy this dependency? Maybe I miss something obvious. – artistCoder Apr 25 '18 at 11:25
  • Have you checked jhipster BOM? https://github.com/avipster/jhipster/ you can slo show the effective dependencies using maven/gradle – Gaël Marziou Apr 25 '18 at 11:43

0 Answers0