zoukankan      html  css  js  c++  java
  • 配置shiro ehcache 出现这个异常,(未解决) java.lang.NoClassDefFoundError: org/terracotta/statistics/StatisticsManager

    参考 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">

    就可以正常启动了。

  • 相关阅读:
    Maven关于web.xml中Servlet和Servlet映射的问题
    intellij idea的Maven项目运行报程序包找不到的错误
    修改Maven项目默认JDK版本
    刷题15. 3Sum
    刷题11. Container With Most Water
    刷题10. Regular Expression Matching
    刷题5. Longest Palindromic Substring
    刷题4. Median of Two Sorted Arrays
    刷题3. Longest Substring Without Repeating Characters
    刷题2. Add Two Numbers
  • 原文地址:https://www.cnblogs.com/snhk/p/10801179.html
Copyright © 2011-2022 走看看