1. 程式人生 > >配置shiro ehcache 出現這個異常,(未解決) java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager

配置shiro ehcache 出現這個異常,(未解決) java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager

pro shiro edi tps 多個 ppc 導入 XML 默認

參考 https://www.cnblogs.com/zfding/p/8536480.html

Caused by: org.springframework.beans.FatalBeanException: Error initializing bean [cacheManager]; nested exception is org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager

at org.apache.shiro.spring.LifecycleBeanPostProcessor.postProcessBeforeInitialization(LifecycleBeanPostProcessor.java:91)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 44 more
Caused by: org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager
at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:223)
at org.apache.shiro.cache.ehcache.EhCacheManager.init(EhCacheManager.java:198)
at org.apache.shiro.spring.LifecycleBeanPostProcessor.postProcessBeforeInitialization(LifecycleBeanPostProcessor.java:89)
... 47 more
Caused by: net.sf.ehcache.CacheException: java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager
at net.sf.ehcache.CacheManager.init(CacheManager.java:415)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:352)
at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:212)
... 49 more
Caused by: java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager
at net.sf.ehcache.statistics.StatisticBuilder$OperationStatisticBuilder.build(StatisticBuilder.java:79)
at net.sf.ehcache.Cache.<init>(Cache.java:260)
at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:296)
at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:219)
at net.sf.ehcache.CacheManager.configure(CacheManager.java:754)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:455)
at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
... 51 more
Caused by: java.lang.ClassNotFoundException: org.terracotta.statistics.StatisticsManager
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1945)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1788)
... 58 more

導入ehcache-3、ehcache-2 jar 的都不行,shiro.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" 
       xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation=
       "http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd">
    <!-- Shiro主過濾器本身功能十分強大,它支持任何基於URL路徑表達式的、自定義的過濾器 -->
     <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean" >
         <property name="securityManager" ref="securityManager"/>
         <!-- 當訪問需要認證的資源時,如果沒有認證,將自動跳到該url
             如果不配置該屬性,默認為根目錄下的login.jsp         -->
         <property name="loginUrl" value="/login.jsp"></property>
         <!-- 配置成功後跳轉到哪個url上,通常不設置,默認認證成功後跳轉上上一個url -->
        <property name="successUrl" value="/main.jsp" ></property>
         <!-- 沒有權限訪問資源時跳轉的頁面 -->
         <property name="unauthorizedUrl" value="refuse"></property>
         <!-- shiro的過濾器鏈  具體配置需要攔截哪些URL,以及訪問對應的URL時
         使用Shiro的默認Filter進行攔截-->
         <property name="filterChainDefinitions">
        <!--anon  任何人都可以訪問
            authc 必須是登錄之後才能訪問,不包括remember me
            user  登錄用戶才可以訪問
            perms 指定過濾規則,擴展使用
        -->
             <value>
                 /toLogin=anon
                 /login-s=anon
                 /logout=logout
                 /main=user
                 /**=anon
             </value>
         </property>
     </bean>
     <!-- authc過濾器 -->
     <bean id="authc" class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">
         <property name="usernameParam" value="uname"></property>
         <property name="passwordParam" value="pwd" ></property>
         <property name="rememberMeParam" value="rememberMe"></property>
     </bean>
     <!-- logout過濾器 -->
     <bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
         <property name="redirectUrl" value="/toLogin"></property>
     </bean>
     <!-- 緩存管理器 -->
     <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
         <property name="cacheManagerConfigFile" value="classpath:ehcache-shiro.xml"></property>
     </bean>
     <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
         <!-- 若有多個Realm,可使用realms 代替 -->
         <property name="realm" ref="userRealm"></property>
         <property name="cacheManager" ref="cacheManager"></property>
         <property name="sessionManager" ref="sessionManager"></property>
         <property name="rememberMeManager" ref="rememberMeManager"></property>
     </bean>
     <bean id="userRealm" class="com.bjsxt.realm.UserRealm">
         <property name="credentialsMatcher" ref="credentialsMatcher" ></property>
     </bean>
     <!-- 會話管理器 -->
     <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
         <property name="globalSessionTimeout" value="300000"></property>
         <!-- 刪除無效session -->
         <property name="deleteInvalidSessions" value="true"></property>
     </bean>
     <!-- 記住我配置 -->
     <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
         <property name="cookie" ref="rememberMeCookie"></property>
     </bean>
     <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie ">
         <property name="maxAge" value="604800" />
         <!-- 設置cookie的名稱 -->
         <property name="name" value="rememberMe"></property>
     </bean>
     <!-- 必須配置lifecycleBeanPostProcessor:管理shiro中常見的對象 -->
     <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" ></bean>
     <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
         <property name="hashAlgorithmName" value="md5"></property>
         <property name="hashIterations" value="10"></property>
     </bean>
     
 </beans>
        

shiro.xml換了shiro自帶的緩存

 <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager">

就可以正常啟動了。

配置shiro ehcache 出現這個異常,(未解決) java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager