Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yoho-search
/
yoho-search-service
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
hugufei
9 years ago
Commit
e7471943cf37a6ce69b78be814f5d600ebd8fd47
1 parent
8c52edf8
update
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
4 deletions
service/src/main/java/com/yoho/search/cache/CacheService.java
service/src/main/java/com/yoho/search/common/SearchPropertyPlaceholderConfigurer.java
web/src/main/resources/META-INF/spring/spring-web-context.xml
service/src/main/java/com/yoho/search/cache/CacheService.java
View file @
e747194
...
...
@@ -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"
);
...
...
service/src/main/java/com/yoho/search/common/SearchPropertyPlaceholderConfigurer.java
0 → 100644
View file @
e747194
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
);
}
}
...
...
web/src/main/resources/META-INF/spring/spring-web-context.xml
View file @
e747194
...
...
@@ -22,7 +22,7 @@
<!-- 打开aop 注解 -->
<aop:aspectj-autoproxy
proxy-target-class=
"true"
/>
<bean
id=
"search
ConfigServerPropertyConfigurer"
class=
"org.springframework.beans.factory.config.
PropertyPlaceholderConfigurer"
>
<bean
id=
"search
PropertyPlaceholderConfigurer"
class=
"com.yoho.search.common.Search
PropertyPlaceholderConfigurer"
>
<property
name=
"ignoreUnresolvablePlaceholders"
value=
"true"
/>
<property
name=
"locations"
>
<list>
...
...
Please
register
or
login
to post a comment