1. 程式人生 > >解決異常 ApplicationEventMulticaster not initialized

解決異常 ApplicationEventMulticaster not initialized

異常資訊

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Thu Nov 22 14:50:17 CST 2018]; root of context hierarchy

該異常出現的形式各種各樣, 經過各種排查最終確定我專案出現該異常的原因是因為ehcache中少配置了一個<cache>標籤中必需配置的屬性, 

原配置

  <defaultCache eternal="false"
                  maxElementsInMemory="10000"
                  maxElementsOnDisk="0"
                  overflowToDisk="false"
                  diskPersistent="false"
                  timeToIdleSeconds="0"
                  timeToLiveSeconds="0"
                  diskSpoolBufferSizeMB="100"
                  memoryStoreEvictionPolicy="FIFO" />

    <!--app中的token快取-->
    <cache name="appTokenCache"
           eternal="true"
           overflowToDisk="true"
           diskPersistent="true"
           memoryStoreEvictionPolicy="FIFO" />

在<cache>標籤中少配置了  maxElementsInMemory="1000" 這個必需要有的屬性才導致的結果

一直傻傻的以為<cache>標籤預設會繼承<defaultCache>內的所有屬性,

修改後的配置

    <defaultCache eternal="false"
                  maxElementsInMemory="10000"
                  maxElementsOnDisk="0"
                  overflowToDisk="false"
                  diskPersistent="false"
                  timeToIdleSeconds="0"
                  timeToLiveSeconds="0"
                  diskSpoolBufferSizeMB="100"
                  memoryStoreEvictionPolicy="FIFO" />

    <!--app中的token快取-->
    <cache name="appTokenCache"
           eternal="true"
           maxElementsInMemory="1000"
           overflowToDisk="true"
           diskPersistent="true"
           memoryStoreEvictionPolicy="FIFO" />

問題解決,