spring注解方式实现Cache的简单Demo

第一步:加入所依赖的jar包

 
        
            org.slf4j
            slf4j-api
            1.7.21
        
        
            net.sf.ehcache
            ehcache-core
            2.6.6
        
        
            net.sf.ehcache
            ehcache
            2.8.3
        
        
            org.springframework
            spring-context-support
            ${org.springframework-version}
        
        
            com.googlecode.ehcache-spring-annotations
            ehcache-spring-annotations
            1.2.0
        
第二步: 加入ehcache.xml和ehcache.xsd配置文件

ehcache.xml配置文件如下所示:


    
        
        
        

        

        

        

        

        

        

        

        

    
ehcache.xsd的配置文件如下所示:




    
        
            
                
                
                
                
                
                
                
                
                
                
            
            
            
            
            
            
            
            
            
        
    
    
        
            
            
            
            
            
            
            
            
            
        
    
    
        
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
                
                    
                        
                            
                        
                    
                
            
            
            
            
        
    
    
    
        
            
                
                
                
                
                
                
                
                
                
                
                
                
                
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
    
        
            
                
                
                
                
                
                
                
                
                
                
                
                
                
                
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
    
        
            
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
        
    
    
        
        	
        	
        	
        	
        	
        	
        
    

    
      
        
          
        
        
        
        
      
    

    
        
            
        
    

    
        
            
                
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
    
        
            
            
        
    
    
        
            
                
            
            
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
            
            
        
    
    
        
            
            
            
        
    
    
        
            
            
        
    
    
        
            
            
        
    

    
        
            
            
            
            
        
    

    
        
            
                
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    
    
        
            
            
        
    
    
        
            
            
            
        
    

    
        
            
        
    

    
        
            
        
    

    
        
            
            
        
    

	
	    
            
            
	    
	
	
	
	    
	        
	        
	        
	        
	    
	
	
    
        
            
            
        
    

    
        
            
            
            
        
    
    
        
            
        
    
    
        
            
        
    


第四步:在xxx-service.xml文件中加入如下配置:


    
    
    
        
    

    
    
        
    

第5步:在需要缓存的service或者biz的方法上加上对应的注:

@Cacheable(value = "propConfigCache",key = "#dateStr+'skynet'")





你可能感兴趣的:(spring注解方式实现Cache的简单Demo)