Authored by hugufei

update

... ... @@ -9,12 +9,12 @@ import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.yoho.search.cache.impl.EhCache;
import com.yoho.search.cache.impl.RedisCache;
import com.yoho.search.cache.model.CacheObject;
import com.yoho.search.common.SearchPropertyPlaceholderConfigurer;
import com.yoho.search.common.SpringContextHolder;
import com.yoho.search.exception.CacheException;
... ... @@ -28,12 +28,14 @@ public class CacheService{
@Autowired
private SpringContextHolder springContextHolder;
@Value("#{search.cache.type}")
private String searchCacheType;
@Autowired
private SearchPropertyPlaceholderConfigurer searchPropertyPlaceholderConfigurer;
public CacheInterface cacheInterface;
@PostConstruct
void init(){
String searchCacheType = (String)searchPropertyPlaceholderConfigurer.getContextProperty("search.cache.type");
if(searchCacheType!=null && searchCacheType.equalsIgnoreCase("redisCache")){
cacheInterface = springContextHolder.getBean("redisCache", RedisCache.class);
logger.info("search.cache.type is redisCache");
... ...
package com.yoho.search.common;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class SearchPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private static Map<String, Object> ctxPropertiesMap;
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
super.processProperties(beanFactory, props);
// load properties to ctxPropertiesMap
ctxPropertiesMap = new HashMap<String, Object>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
ctxPropertiesMap.put(keyStr, value);
}
}
public Object getContextProperty(String name) {
return ctxPropertiesMap.get(name);
}
}
... ...
... ... @@ -22,7 +22,7 @@
<!-- 打开aop 注解 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="searchConfigServerPropertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<bean id="searchPropertyPlaceholderConfigurer" class="com.yoho.search.common.SearchPropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
... ...