springmvc 结合 ehcache
2016-07-02 22:30
411 查看
ehcache 版本使用ehcache-2.10.2.jar
需要的包
ehcache-2.10.2.jar
slf4j-api-1.7.7.jar
slf4j-jdk14-1.7.7.jar
使用log4j日志框架需要的包
slf4j-log4j12-1.7.7.jar
log4j-1.2.17.jar
全部包,下载地址
http://download.csdn.net/detail/wangzhiqiang123456/9565929
配置问题文件
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir/ehcache"/>
<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"/>
<cache name="menuCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
applicationContext.xml 只有关于ehcache的配置,其他配置没有贴出来
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<!--开启缓存注解-->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- 缓存配置开始 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
<!-- 缓存配置结束 -->
</beans>
测试方法
@Cacheable(value="menuCache")
public String getkey(String k)
{
log.debug("进来了");
return "55985985555";
}
log4j.properties
#定义根日志级别和输出端(定义了两个输出端)
#log4j.rootLogger=DEBUG,CONSOLE,D,E
log4j.rootLogger=DEBUG,CONSOLE
#定义第一个输出端,输出到控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c(%L) - %m%n
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
#定义具体某个包下的日志输出级别
log4j.logger.org.springframework=ERROR
slf4j+log4j出现的问题
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
错误提示,在两个包中存在相同的StaticLoggerBinder.class 删除一个class即可
需要的包
ehcache-2.10.2.jar
slf4j-api-1.7.7.jar
slf4j-jdk14-1.7.7.jar
使用log4j日志框架需要的包
slf4j-log4j12-1.7.7.jar
log4j-1.2.17.jar
全部包,下载地址
http://download.csdn.net/detail/wangzhiqiang123456/9565929
配置问题文件
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir/ehcache"/>
<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"/>
<cache name="menuCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
applicationContext.xml 只有关于ehcache的配置,其他配置没有贴出来
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<!--开启缓存注解-->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- 缓存配置开始 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
<!-- 缓存配置结束 -->
</beans>
测试方法
@Cacheable(value="menuCache")
public String getkey(String k)
{
log.debug("进来了");
return "55985985555";
}
log4j.properties
#定义根日志级别和输出端(定义了两个输出端)
#log4j.rootLogger=DEBUG,CONSOLE,D,E
log4j.rootLogger=DEBUG,CONSOLE
#定义第一个输出端,输出到控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c(%L) - %m%n
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
#定义具体某个包下的日志输出级别
log4j.logger.org.springframework=ERROR
slf4j+log4j出现的问题
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:D:/Oracle/Middleware/user_projects/domains/base_qumancheng/servers/AdminServer/tmp/_WL_user/_appsdir_ainmeweb_dir/e5r7ej/war/WEB-INF/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
错误提示,在两个包中存在相同的StaticLoggerBinder.class 删除一个class即可
相关文章推荐
- java框架之springmvc06(数据验证)
- JAVA 多态-深层次理解
- java并发锁-Lock接口
- java文件基本操作
- leetcode 218. The Skyline Problem java代码
- Java中使用Statement接口SQL语句
- Java 工程师的学习线路图。
- Java设计模式之单例模式
- Java总结篇系列:Java泛型
- Java核心技术卷1 第十四章 多线程
- Spring-自定义事件发布
- Maven整合Springmvc + Mybatis + Spring
- InheritableThreadLocal用法与ThreadLocal的区别
- java中哈希表,Map,HashCode,Equals等介绍
- JAVA设计模式之单例模式
- Java注释模版设置
- java—程序绑定
- Java基础之(三) 函数
- Java中的随机数
- Java编码规范(常用重点)