`

Spring AOP+EHCache简单缓存系统解决方案

    博客分类:
  • j2ee
阅读更多

需要使用Spring来实现一个Cache简单的解决方案,具体需求如下:使用任意一个现有开源Cache Framework,要求可以Cache系统中Service或则DAO层的get/find等方法返回结果,如果数据更新(使用Create/update/delete方法),则刷新cache中相应的内容。 MethodCacheInterceptor.java

Java代码 复制代码
  1. package com.co.cache.ehcache;   
  2.   
  3. import java.io.Serializable;   
  4.   
  5. import net.sf.ehcache.Cache;   
  6. import net.sf.ehcache.Element;   
  7.   
  8. import org.aopalliance.intercept.MethodInterceptor;   
  9. import org.aopalliance.intercept.MethodInvocation;   
  10. import org.apache.commons.logging.Log;   
  11. import org.apache.commons.logging.LogFactory;   
  12. import org.springframework.beans.factory.InitializingBean;   
  13. import org.springframework.util.Assert;   
  14.   
  15. public class MethodCacheInterceptor implements MethodInterceptor, InitializingBean   
  16. {   
  17.     private static final Log logger = LogFactory.getLog(MethodCacheInterceptor.class);   
  18.   
  19.     private Cache cache;   
  20.   
  21.     public void setCache(Cache cache) {   
  22.         this.cache = cache;   
  23.     }   
  24.   
  25.     public MethodCacheInterceptor() {   
  26.         super();   
  27.     }   
  28.   
  29.     /**  
  30.      * 拦截Service/DAO的方法,并查找该结果是否存在,如果存在就返回cache中的值,  
  31.      * 否则,返回数据库查询结果,并将查询结果放入cache  
  32.      */  
  33.     public Object invoke(MethodInvocation invocation) throws Throwable {   
  34.         String targetName = invocation.getThis().getClass().getName();   
  35.         String methodName = invocation.getMethod().getName();   
  36.         Object[] arguments = invocation.getArguments();   
  37.         Object result;   
  38.        
  39.         logger.debug("Find object from cache is " + cache.getName());   
  40.            
  41.         String cacheKey = getCacheKey(targetName, methodName, arguments);   
  42.         Element element = cache.get(cacheKey);   
  43.   
  44.         if (element == null) {   
  45.             logger.debug("Hold up method , Get method result and create cache........!");   
  46.             result = invocation.proceed();   
  47.             element = new Element(cacheKey, (Serializable) result);   
  48.             cache.put(element);   
  49.         }   
  50.         return element.getValue();   
  51.     }   
  52.   
  53.     /**  
  54.      * 获得cache key的方法,cache key是Cache中一个Element的唯一标识  
  55.      * cache key包括 包名+类名+方法名,如com.co.cache.service.UserServiceImpl.getAllUser  
  56.      */  
  57.     private String getCacheKey(String targetName, String methodName, Object[] arguments) {   
  58.         StringBuffer sb = new StringBuffer();   
  59.         sb.append(targetName).append(".").append(methodName);   
  60.         if ((arguments != null) && (arguments.length != 0)) {   
  61.             for (int i = 0; i < arguments.length; i++) {   
  62.                 sb.append(".").append(arguments[i]);   
  63.             }   
  64.         }   
  65.         return sb.toString();   
  66.     }   
  67.        
  68.     /**  
  69.      * implement InitializingBean,检查cache是否为空  
  70.      */  
  71.     public void afterPropertiesSet() throws Exception {   
  72.         Assert.notNull(cache, "Need a cache. Please use setCache(Cache) create it.");   
  73.     }   
  74.   
  75. }  
package com.co.cache.ehcache;

import java.io.Serializable;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class MethodCacheInterceptor implements MethodInterceptor, InitializingBean
{
	private static final Log logger = LogFactory.getLog(MethodCacheInterceptor.class);

	private Cache cache;

	public void setCache(Cache cache) {
		this.cache = cache;
	}

	public MethodCacheInterceptor() {
		super();
	}

	/**
	 * 拦截Service/DAO的方法,并查找该结果是否存在,如果存在就返回cache中的值,
	 * 否则,返回数据库查询结果,并将查询结果放入cache
	 */
	public Object invoke(MethodInvocation invocation) throws Throwable {
		String targetName = invocation.getThis().getClass().getName();
		String methodName = invocation.getMethod().getName();
		Object[] arguments = invocation.getArguments();
		Object result;
	
		logger.debug("Find object from cache is " + cache.getName());
		
		String cacheKey = getCacheKey(targetName, methodName, arguments);
		Element element = cache.get(cacheKey);

		if (element == null) {
			logger.debug("Hold up method , Get method result and create cache........!");
			result = invocation.proceed();
			element = new Element(cacheKey, (Serializable) result);
			cache.put(element);
		}
		return element.getValue();
	}

	/**
	 * 获得cache key的方法,cache key是Cache中一个Element的唯一标识
	 * cache key包括 包名+类名+方法名,如com.co.cache.service.UserServiceImpl.getAllUser
	 */
	private String getCacheKey(String targetName, String methodName, Object[] arguments) {
		StringBuffer sb = new StringBuffer();
		sb.append(targetName).append(".").append(methodName);
		if ((arguments != null) && (arguments.length != 0)) {
			for (int i = 0; i < arguments.length; i++) {
				sb.append(".").append(arguments[i]);
			}
		}
		return sb.toString();
	}
	
	/**
	 * implement InitializingBean,检查cache是否为空
	 */
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(cache, "Need a cache. Please use setCache(Cache) create it.");
	}

}



上面的代码中可以看到,在方法public Object invoke(MethodInvocation invocation) 中,完成了搜索Cache/新建cache的功能。

Java代码 复制代码
  1. Element element = cache.get(cacheKey);  
Element element = cache.get(cacheKey);


这句代码的作用是获取cache中的element,如果cacheKey所对应的element不存在,将会返回一个null值

Java代码 复制代码
  1. result = invocation.proceed();  
result = invocation.proceed();


这句代码的作用是获取所拦截方法的返回值,详细请查阅AOP相关文档。

随后,再建立一个拦截器MethodCacheAfterAdvice,作用是在用户进行create/update/delete操作时来刷新/remove相关cache内容,这个拦截器实现了AfterReturningAdvice接口,将会在所拦截的方法执行后执行在public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3)方法中所预定的操作

Java代码 复制代码
  1. package com.co.cache.ehcache;   
  2.   
  3. import java.lang.reflect.Method;   
  4. import java.util.List;   
  5.   
  6. import net.sf.ehcache.Cache;   
  7.   
  8. import org.apache.commons.logging.Log;   
  9. import org.apache.commons.logging.LogFactory;   
  10. import org.springframework.aop.AfterReturningAdvice;   
  11. import org.springframework.beans.factory.InitializingBean;   
  12. import org.springframework.util.Assert;   
  13.   
  14. public class MethodCacheAfterAdvice implements AfterReturningAdvice, InitializingBean   
  15. {   
  16.     private static final Log logger = LogFactory.getLog(MethodCacheAfterAdvice.class);   
  17.   
  18.     private Cache cache;   
  19.   
  20.     public void setCache(Cache cache) {   
  21.         this.cache = cache;   
  22.     }   
  23.   
  24.     public MethodCacheAfterAdvice() {   
  25.         super();   
  26.     }   
  27.   
  28.     public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable {   
  29.         String className = arg3.getClass().getName();   
  30.         List list = cache.getKeys();   
  31.         for(int i = 0;i<list.size();i++){   
  32.             String cacheKey = String.valueOf(list.get(i));   
  33.             if(cacheKey.startsWith(className)){   
  34.                 cache.remove(cacheKey);   
  35.                 logger.debug("remove cache " + cacheKey);   
  36.             }   
  37.         }   
  38.     }   
  39.   
  40.     public void afterPropertiesSet() throws Exception {   
  41.         Assert.notNull(cache, "Need a cache. Please use setCache(Cache) create it.");   
  42.     }   
  43.   
  44. }  
package com.co.cache.ehcache;

import java.lang.reflect.Method;
import java.util.List;

import net.sf.ehcache.Cache;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

public class MethodCacheAfterAdvice implements AfterReturningAdvice, InitializingBean
{
	private static final Log logger = LogFactory.getLog(MethodCacheAfterAdvice.class);

	private Cache cache;

	public void setCache(Cache cache) {
		this.cache = cache;
	}

	public MethodCacheAfterAdvice() {
		super();
	}

	public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable {
		String className = arg3.getClass().getName();
		List list = cache.getKeys();
		for(int i = 0;i<list.size();i++){
			String cacheKey = String.valueOf(list.get(i));
			if(cacheKey.startsWith(className)){
				cache.remove(cacheKey);
				logger.debug("remove cache " + cacheKey);
			}
		}
	}

	public void afterPropertiesSet() throws Exception {
		Assert.notNull(cache, "Need a cache. Please use setCache(Cache) create it.");
	}

}


上面的代码很简单,实现了afterReturning方法实现自AfterReturningAdvice接口,方法中所定义的内容将会在目标方法执行后执行,在该方法中

Java代码 复制代码
  1. String className = arg3.getClass().getName();  
String className = arg3.getClass().getName();

的作用是获取目标class的全名,如:com.co.cache.test.TestServiceImpl,然后循环cache的key list,remove cache中所有和该class相关的element。

随后,开始配置ehCache的属性,ehCache需要一个xml文件来设置ehCache相关的一些属性,如最大缓存数量、cache刷新的时间等等.
ehcache.xml

Java代码 复制代码
  1. <ehcache>   
  2.     <diskStore path="c:\\myapp\\cache"/>   
  3.     <defaultCache   
  4.         maxElementsInMemory="1000"  
  5.         eternal="false"  
  6.         timeToIdleSeconds="120"  
  7.         timeToLiveSeconds="120"  
  8.         overflowToDisk="true"  
  9.         />   
  10.   <cache name="DEFAULT_CACHE"  
  11.         maxElementsInMemory="10000"  
  12.         eternal="false"  
  13.         timeToIdleSeconds="300000"  
  14.         timeToLiveSeconds="600000"  
  15.         overflowToDisk="true"  
  16.         />   
  17. </ehcache>  
<ehcache>
	<diskStore path="c:\\myapp\\cache"/>
	<defaultCache
        maxElementsInMemory="1000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="true"
        />
  <cache name="DEFAULT_CACHE"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300000"
        timeToLiveSeconds="600000"
        overflowToDisk="true"
        />
</ehcache>


配置每一项的详细作用不再详细解释,有兴趣的请google下 ,这里需要注意一点defaultCache标签定义了一个默认的Cache,这个Cache是不能删除的,否则会抛出No default cache is configured异常。另外,由于使用拦截器来刷新Cache内容,因此在定义cache生命周期时可以定义较大的数值,timeToIdleSeconds="300000" timeToLiveSeconds="600000",好像还不够大?

然后,在将Cache和两个拦截器配置到Spring,这里没有使用2.0里面AOP的标签。
cacheContext.xml

Java代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">   
  3. <beans>   
  4.     <!-- 引用ehCache的配置 -->   
  5.     <bean id="defaultCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">   
  6.       <property name="configLocation">   
  7.         <value>ehcache.xml</value>   
  8.       </property>   
  9.     </bean>   
  10.        
  11.     <!-- 定义ehCache的工厂,并设置所使用的Cache name -->   
  12.     <bean id="ehCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">   
  13.       <property name="cacheManager">   
  14.         <ref local="defaultCacheManager"/>   
  15.       </property>   
  16.       <property name="cacheName">   
  17.           <value>DEFAULT_CACHE</value>   
  18.       </property>   
  19.     </bean>   
  20.   
  21.     <!-- find/create cache拦截器 -->   
  22.     <bean id="methodCacheInterceptor" class="com.co.cache.ehcache.MethodCacheInterceptor">   
  23.       <property name="cache">   
  24.         <ref local="ehCache" />   
  25.       </property>   
  26.     </bean>   
  27.     <!-- flush cache拦截器 -->   
  28.     <bean id="methodCacheAfterAdvice" class="com.co.cache.ehcache.MethodCacheAfterAdvice">   
  29.       <property name="cache">   
  30.         <ref local="ehCache" />   
  31.       </property>   
  32.     </bean>   
  33.        
  34.     <bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">   
  35.       <property name="advice">   
  36.         <ref local="methodCacheInterceptor"/>   
  37.       </property>   
  38.       <property name="patterns">   
  39.         <list>   
  40.             <value>.*find.*</value>   
  41.             <value>.*get.*</value>   
  42.         </list>   
  43.       </property>   
  44.     </bean>   
  45.     <bean id="methodCachePointCutAdvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">   
  46.       <property name="advice">   
  47.         <ref local="methodCacheAfterAdvice"/>   
  48.       </property>   
  49.       <property name="patterns">   
  50.         <list>   
  51.           <value>.*create.*</value>   
  52.           <value>.*update.*</value>   
  53.           <value>.*delete.*</value>   
  54.         </list>   
  55.       </property>   
  56.     </bean>   
  57. </beans>  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	<!-- 引用ehCache的配置 -->
	<bean id="defaultCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
	  <property name="configLocation">
		<value>ehcache.xml</value>
	  </property>
	</bean>
	
	<!-- 定义ehCache的工厂,并设置所使用的Cache name -->
	<bean id="ehCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
	  <property name="cacheManager">
		<ref local="defaultCacheManager"/>
	  </property>
	  <property name="cacheName">
		  <value>DEFAULT_CACHE</value>
	  </property>
	</bean>

	<!-- find/create cache拦截器 -->
	<bean id="methodCacheInterceptor" class="com.co.cache.ehcache.MethodCacheInterceptor">
	  <property name="cache">
		<ref local="ehCache" />
	  </property>
	</bean>
	<!-- flush cache拦截器 -->
	<bean id="methodCacheAfterAdvice" class="com.co.cache.ehcache.MethodCacheAfterAdvice">
	  <property name="cache">
		<ref local="ehCache" />
	  </property>
	</bean>
	
	<bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
	  <property name="advice">
		<ref local="methodCacheInterceptor"/>
	  </property>
	  <property name="patterns">
		<list>
			<value>.*find.*</value>
			<value>.*get.*</value>
		</list>
	  </property>
	</bean>
	<bean id="methodCachePointCutAdvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
	  <property name="advice">
		<ref local="methodCacheAfterAdvice"/>
	  </property>
	  <property name="patterns">
		<list>
		  <value>.*create.*</value>
		  <value>.*update.*</value>
		  <value>.*delete.*</value>
		</list>
	  </property>
	</bean>
</beans>


上面的代码最终创建了两个"切入点",methodCachePointCut和methodCachePointCutAdvice,分别用于拦截不同方法名的方法,可以根据需要任意增加所需要拦截方法的名称。
需要注意的是

Java代码 复制代码
  1. <bean id="ehCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">   
  2.       <property name="cacheManager">   
  3.         <ref local="defaultCacheManager"/>   
  4.       </property>   
  5.       <property name="cacheName">   
  6.           <value>DEFAULT_CACHE</value>   
  7.       </property>   
  8.     </bean>  
<bean id="ehCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
	  <property name="cacheManager">
		<ref local="defaultCacheManager"/>
	  </property>
	  <property name="cacheName">
		  <value>DEFAULT_CACHE</value>
	  </property>
	</bean>


如果cacheName属性内设置的name在ehCache.xml中无法找到,那么将使用默认的cache(defaultCache标签定义).

事实上到了这里,一个简单的Spring + ehCache Framework基本完成了,为了测试效果,举一个实际应用的例子,定义一个TestService和它的实现类TestServiceImpl,里面包含

两个方法getAllObject()和updateObject(Object Object),具体代码如下
TestService.java

Java代码 复制代码
  1. package com.co.cache.test;   
  2.   
  3. import java.util.List;   
  4.   
  5. public interface TestService {   
  6.     public List getAllObject();   
  7.   
  8.     public void updateObject(Object Object);   
  9. }  
package com.co.cache.test;

import java.util.List;

public interface TestService {
	public List getAllObject();

	public void updateObject(Object Object);
}



TestServiceImpl.java

Java代码 复制代码
  1. package com.co.cache.test;   
  2.   
  3. import java.util.List;   
  4.   
  5. public class TestServiceImpl implements TestService   
  6. {   
  7.     public List getAllObject() {   
  8.         System.out.println("---TestService:Cache内不存在该element,查找并放入Cache!");   
  9.         return null;   
  10.     }   
  11.   
  12.     public void updateObject(Object Object) {   
  13.         System.out.println("---TestService:更新了对象,这个Class产生的cache都将被remove!");   
  14.     }   
  15. }  
package com.co.cache.test;

import java.util.List;

public class TestServiceImpl implements TestService
{
	public List getAllObject() {
		System.out.println("---TestService:Cache内不存在该element,查找并放入Cache!");
		return null;
    }

	public void updateObject(Object Object) {
		System.out.println("---TestService:更新了对象,这个Class产生的cache都将被remove!");
    }
}


使用Spring提供的AOP进行配置
applicationContext.xml

Java代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">   
  3.   
  4. <beans>   
  5.     <import resource="cacheContext.xml"/>   
  6.        
  7.     <bean id="testServiceTarget" class="com.co.cache.test.TestServiceImpl"/>   
  8.        
  9.     <bean id="testService" class="org.springframework.aop.framework.ProxyFactoryBean">   
  10.       <property name="target">   
  11.           <ref local="testServiceTarget"/>   
  12.       </property>   
  13.       <property name="interceptorNames">   
  14.         <list>   
  15.           <value>methodCachePointCut</value>   
  16.           <value>methodCachePointCutAdvice</value>   
  17.         </list>   
  18.       </property>   
  19.     </bean>   
  20. </beans>  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
	<import resource="cacheContext.xml"/>
	
	<bean id="testServiceTarget" class="com.co.cache.test.TestServiceImpl"/>
	
    <bean id="testService" class="org.springframework.aop.framework.ProxyFactoryBean">
	  <property name="target">
		  <ref local="testServiceTarget"/>
	  </property>
	  <property name="interceptorNames">
		<list>
		  <value>methodCachePointCut</value>
		  <value>methodCachePointCutAdvice</value>
		</list>
	  </property>
	</bean>
</beans>


这里一定不能忘记import cacheContext.xml文件,不然定义的两个拦截器就没办法使用了。

最后,写一个测试的代码
MainTest.java

Java代码 复制代码
  1. package com.co.cache.test;   
  2.   
  3. import org.springframework.context.ApplicationContext;   
  4. import org.springframework.context.support.ClassPathXmlApplicationContext;   
  5.   
  6. public class MainTest{   
  7.     public static void main(String args[]){   
  8.         String DEFAULT_CONTEXT_FILE = "/applicationContext.xml";   
  9.         ApplicationContext context =  new ClassPathXmlApplicationContext(DEFAULT_CONTEXT_FILE);   
  10.         TestService testService = (TestService)context.getBean("testService");   
  11.   
  12.         System.out.println("1--第一次查找并创建cache");   
  13.         testService.getAllObject();   
  14.            
  15.         System.out.println("2--在cache中查找");   
  16.         testService.getAllObject();   
  17.            
  18.         System.out.println("3--remove cache");   
  19.         testService.updateObject(null);   
  20.            
  21.         System.out.println("4--需要重新查找并创建cache");   
  22.         testService.getAllObject();   
  23.     }      
  24. }  
package com.co.cache.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest{
	public static void main(String args[]){
		String DEFAULT_CONTEXT_FILE = "/applicationContext.xml";
		ApplicationContext context =  new ClassPathXmlApplicationContext(DEFAULT_CONTEXT_FILE);
		TestService testService = (TestService)context.getBean("testService");

		System.out.println("1--第一次查找并创建cache");
		testService.getAllObject();
		
		System.out.println("2--在cache中查找");
		testService.getAllObject();
		
		System.out.println("3--remove cache");
		testService.updateObject(null);
		
		System.out.println("4--需要重新查找并创建cache");
		testService.getAllObject();
	}	
}



运行,结果如下

Java代码 复制代码
  1. 1--第一次查找并创建cache   
  2. ---TestService:Cache内不存在该element,查找并放入Cache!   
  3. 2--在cache中查找   
  4. 3--remove cache   
  5. ---TestService:更新了对象,这个Class产生的cache都将被remove!   
  6. 4--需要重新查找并创建cache   
  7. ---TestService:Cache内不存在该element,查找并放入Cache!  
1--第一次查找并创建cache
---TestService:Cache内不存在该element,查找并放入Cache!
2--在cache中查找
3--remove cache
---TestService:更新了对象,这个Class产生的cache都将被remove!
4--需要重新查找并创建cache
---TestService:Cache内不存在该element,查找并放入Cache!



可以看到,第一步执行getAllObject(),执行TestServiceImpl内的方法,并创建了cache,在第二次执行getAllObject()方法时,由于cache有该方法的缓存,直接从cache中get出方法的结果,所以没有打印出TestServiceImpl中的内容,而第三步,调用了updateObject方法,和TestServiceImpl相关的cache被remove,所以在第四步执行时,又执行TestServiceImpl中的方法,创建Cache。

 

注意的问题

我们知道,Cache为ehcache.XML配置文件里面所定义的缓存类别,获取某一特定的缓存类别的方法如下:
 Cache cache= cacheManager.getCache(cacheName);
cacheName为想获取的缓存类别名。然后象下面方法把某一对象放入上面定义的缓存:
cache.put(new Element(key,(Serializable)value));
key为 放入该缓存中的对象的索引值,value为放入该缓存中key所对应的对象。我们看到,放入缓存中的value必须序列化,Java原生类型<!--StartFragment --> char、int ,原生类型的包装类String、Character、Integer、Number...和集合List的实现类ArrayList都已经实现了Serializable接口,它们都可以直接放到缓存中。这里要注意的是,在方法返回值中经常用到的Iterator,并没有实现Serializable接口,所以Cache 不能缓存返回值类型为Iterator的方法。
    还有一点要注意的是,如果我们要做缓存的方法是在bean的生命周期的初始化阶段调用的(例如setter,init),此时方法缓存拦截器还没被调用执行,那么缓存将不起作用,如做了下面的配置:
<bean id="OrganizationManagerMethodCache" class="org.springFramework.aop.framework.ProxyFactoryBean">
    <property name="target">
        <bean class="com.wzj.rbac.ServiceFacade.OrganizationManager"  init-method="init" autowire="byName"/>     
    </property>
    <property name="interceptorNames">
       <list>
            <value>methodCachePointCut</value>
        </list>
     </property>
</bean>
在init初始方法里面调用的缓存方法将失效。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics