스프링에서 EhCacheManagerFactoryBean
으로 확장하려면 (다소 정직하기 만하면됩니다) 비슷한 작업을 수행했는지 (내 Ehcache xml 파일의 일부 자리 표시자를 바꿉니다. 즉시 Ehcache xml 설정 파일을 생성하십시오.
afterPropertiesSet()
에 CacheManager
인스턴스를 생성하려면 구성을 가리키는 InputStream
을 넘겨주십시오. 내 필터링 물건
@Override
public void afterPropertiesSet() throws IOException, CacheException {
if (this.configLocation != null) {
InputStreamSource finalConfig = new YourResourceWrapper(this.configLocation); // put your custom logic here
InputStream is = finalConfig.getInputStream();
try {
this.cacheManager = (this.shared ? CacheManager.create(is) : new CacheManager(is));
} finally {
IOUtils.closeQuietly(is);
}
} else {
// ...
}
// ...
}
나는 내부적으로 최종 설정을 유지하기 위해 ByteArrayResource
을 사용했다. 하나는 더 멋진 물건을 할 (봄에 대한 지원을하고있다) 프리 마커와 같은 실제 템플릿 엔진을 사용하여 생각할 수하는 주형 "진짜"를
data = IOUtils.toString(source.getInputStream()); // get the original config (configLocation) as string
// do your string manipulation here
Resource finalConfigResource = new ByteArrayResource(data.getBytes());
.
관련 항목 (가능한 dup?) : [여러 프로젝트, 같은 전쟁에서 여러 개의 ehcache.xml을 사용할 수 있습니까?] (http://stackoverflow.com/q/8834993/16487) –