I am upgrading my apps to 7 and have also upgraded...
# questions
u
I am upgrading my apps to 7 and have also upgraded some caches to Ehcache 3. We currently deploy our apps as WAR files to tomcat (10, java 21). Everything is working as expected so far, but when tomcat shuts down, I am seeing an exception from Ehcache
Copy code
java.lang.IllegalStateException: Close not supported from UNINITIALIZED
I am creating the cache beans like this
Copy code
@Configuration
class EhcacheConfig {
    
    @Autowired
    CacheManager cacheManager

    @Bean
    CacheManager cacheManager() {
        log.info('cacheManager() called')
        return CacheManagerBuilder.newCacheManagerBuilder().withCache('cache1', ...).withCache('cache2', ...).build(true)
    }

    @Bean
    Cache<String, Integer> cache1() {
        return cacheManager.getCache('cache1', String, Integer)
    }

    @Bean
    Cache<String, Integer> cache2() {
        return cacheManager.getCache('cache2', String, Integer)
    }
I am not seeing the same error happen when running locally with bootRun. Any ideas here?
j
we too are using ehcache and I haven’t seen this behavior - but we start directly from the jar file using embedded undertow. I only recently converted our application though.
u
Here is the full stack trace that I am seeing
Copy code
java.lang.IllegalStateException: Close not supported from UNINITIALIZED
    at org.ehcache.core.InternalStatus.close(InternalStatus.java:74)
    at org.ehcache.core.StatusTransitioner.close(StatusTransitioner.java:81)
    at org.ehcache.core.EhcacheBase.close(EhcacheBase.java:575)
    at org.ehcache.core.EhcacheManager.removeCache(EhcacheManager.java:213)
    at org.ehcache.core.EhcacheManager.close(EhcacheManager.java:629)
    at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:233)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:798)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:748)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1499)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:707)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1492)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1222)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1183)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:179)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1129)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:510)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:136)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer$SpringBootContextLoaderListener.contextDestroyed(SpringBootServletInitializer.java:266)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4078)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:4688)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:235)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1217)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1206)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:81)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:812)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:235)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1217)
    at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1206)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:81)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:812)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:235)
    at org.apache.catalina.core.StandardService.stopInternal(StandardService.java:466)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:235)
    at org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:913)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:235)
    at org.apache.catalina.startup.Catalina.stop(Catalina.java:833)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:797)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
u
thanks, unfortunately the link doesn't provide much information 😞
j
it sounds like after you create the bean you need to call .init()
so its trying ti close the cache but it was never activated
u
thats what the true means in the build method build(boolean init)
j
maybe there’s another bean on the classpath? have you looked at the registry to see if yours is the only one?
u
I haven't, I will check that now. 🤞
🤞 1