[Spring 프 리 로드] InitialingBean 인터페이스
                                            
 14549 단어  스프링 프 리 로드
                    
InitializingBean 인 터 페 이 스 를 실현 하 는 것 은 Spring 예비 로드 를 실현 하 는 수단 으로 절 차 를 실현 하 는 것 입 니 다.
public class DemoCache implements InitializingBean {
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		
	}
}
 public class DemoCache implements InitializingBean {
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		//              
	}
}
 그러면 우리 의 초기 화 방법 이 실 행 됩 니 다. 그러나 이것 은 한 번 만 실 행 됩 니 다.다음 사용자 가 요청 할 때 도 검색 방법 을 실행 해 야 합 니 다. 그러면 우리 의 검색 은 아무런 의미 가 없 는 것 같 습 니 다. 그래서 우 리 는 우리 가 얻 은 결 과 를 캐 시 에 저장 해 야 합 니 다. 사용자 가 다음 에 요청 할 때 캐 시 에 있 는 데 이 터 를 직접 방문 하여 사용자 체험 을 향상 시 킬 수 있 습 니 다. <?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:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
	       http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">  
           
	<bean id="demoCache" class="com.gaotime.info.product.web.cache.DemoCache"/> 
</beans>
 주: 여기 사용 하 는 ehcache.<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
		p:configLocation="classpath:/cache/ehcache.xml" />
	<!-- cacheManager   ,  ehcache.xml    -->	
	<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
		p:configLocation="classpath:/cache/ehcache.xml" />	
		
	<!--   cacheManager -->
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" 
		p:cacheManager-ref="cacheManagerFactory" />		
		
	<bean id="lowFreCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
	    <property name="cacheManager" ref="cacheManagerFactory" />
	    <property name="cacheName" value="lowFreCache" />
	</bean>
	<bean id="lowFreMethodCacheInterceptor" class="com.gaotime.info.product.web.util.MethodCacheInterceptor">
	    <property name="cache" ref="lowFreCache"/>
	</bean>
	<bean id="lowFreMethodCachePointCut"	class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
		<property name="advice" ref="lowFreMethodCacheInterceptor" />
		<property name="patterns">
			<list>
				 <value>com.lr.service.impl.DemoServiceImpl\.getCount</value>		<!--       -->	  
			</list>
		</property>
	</bean>