Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cc-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
cc-service
Commits
3ca37f01
Commit
3ca37f01
authored
Aug 12, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
缓存前缀设置为applicationName
parent
697a2e5a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
162 additions
and
11 deletions
+162
-11
CacheNames.java
...n/java/com/esv/datacenter/cc/common/cache/CacheNames.java
+5
-5
CacheConfig.java
src/main/java/com/esv/datacenter/cc/config/CacheConfig.java
+25
-3
application-demo.yml
src/main/resources/application-demo.yml
+129
-0
application-dev.yml
src/main/resources/application-dev.yml
+1
-1
application-local.yml
src/main/resources/application-local.yml
+1
-1
application-test.yml
src/main/resources/application-test.yml
+1
-1
No files found.
src/main/java/com/esv/datacenter/cc/common/cache/CacheNames.java
View file @
3ca37f01
...
...
@@ -11,30 +11,30 @@ public class CacheNames {
* author chenfm
* createTime 2020/4/10 14:16
**/
public
static
final
String
API_AUTHORITY
=
"
freight-cc::
apiAuthority"
;
public
static
final
String
API_AUTHORITY
=
"apiAuthority"
;
/**
* description 用户信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public
static
final
String
USER_INFO
=
"
freight-cc::
userInfo"
;
public
static
final
String
USER_INFO
=
"userInfo"
;
/**
* description 系统code对应系统信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public
static
final
String
SYSTEM_BY_CODE
=
"
freight-cc::
systemByCode"
;
public
static
final
String
SYSTEM_BY_CODE
=
"systemByCode"
;
/**
* description 各系统用户权限
* author chenfm
* createTime 2020/4/10 14:16
**/
public
static
final
String
SYSTEM_USER_PERM
=
"
freight-cc::
systemUserPerm"
;
public
static
final
String
SYSTEM_USER_PERM
=
"systemUserPerm"
;
/**
* description 菜单信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public
static
final
String
MENU_INFO
=
"
freight-cc::
menuInfo"
;
public
static
final
String
MENU_INFO
=
"menuInfo"
;
}
src/main/java/com/esv/datacenter/cc/config/CacheConfig.java
View file @
3ca37f01
...
...
@@ -7,9 +7,11 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.CacheKeyPrefix
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheWriter
;
...
...
@@ -30,6 +32,9 @@ import java.util.Map;
@EnableCaching
public
class
CacheConfig
{
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
@Autowired
CacheNameConfig
cacheNameConfig
;
...
...
@@ -87,13 +92,30 @@ public class CacheConfig {
private
RedisCacheConfiguration
getRedisCacheConfigurationWithTtl
(
Integer
seconds
)
{
RedisCacheConfiguration
redisCacheConfiguration
=
RedisCacheConfiguration
.
defaultCacheConfig
();
redisCacheConfiguration
=
redisCacheConfiguration
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jsonSerializer
())
).
entryTtl
(
Duration
.
ofSeconds
(
seconds
));
redisCacheConfiguration
=
redisCacheConfiguration
.
computePrefixWith
(
cacheKeyPrefix
())
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jsonSerializer
()))
.
entryTtl
(
Duration
.
ofSeconds
(
seconds
));
return
redisCacheConfiguration
;
}
/**
* @description 设置缓存key的前缀
* @return org.springframework.data.redis.cache.CacheKeyPrefix
* @author huangChaobin@esvtek.com
* @createTime 2020/07/30 19:49
**/
@Bean
public
CacheKeyPrefix
cacheKeyPrefix
()
{
return
cacheName
->
{
StringBuilder
sBuilder
=
new
StringBuilder
(
8
);
sBuilder
.
append
(
applicationName
).
append
(
"::"
);
sBuilder
.
append
(
cacheName
).
append
(
"::"
);
return
sBuilder
.
toString
();
};
}
/**
* RedisTemplate默认使用的序列化机制是JdkSerializationRedisSerializer,这里我们是用Jackson2JsonRedisSerializer
* @return
...
...
src/main/resources/application-demo.yml
0 → 100644
View file @
3ca37f01
spring
:
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
druid
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://192.168.0.17:3306/iot?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8
username
:
iot
password
:
123456
initial-size
:
5
min-idle
:
5
max-active
:
20
max-wait
:
60000
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT
1
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
filter
:
stat
:
log-slow-sql
:
true
slow-sql-millis
:
1000
merge-sql
:
false
redis
:
host
:
192.168.0.17
port
:
6379
password
:
database
:
3
# 连接超时时间(毫秒)默认是2000ms
timeout
:
5000
jedis
:
pool
:
# 连接池最大连接数(使用负值表示没有限制)
max-active
:
8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait
:
-1
# 连接池中的最大空闲连接
max-idle
:
8
# 连接池中的最小空闲连接
min-idle
:
0
# 集群配置
# cluster:
# 集群地址(使用','分割)
# nodes:
# 一般当此值设置过大时,容易报:Too many Cluster redirections
# max-redirects: 3
cache
:
redis
:
## Entry expiration in milliseconds. By default the entries never expire.
# time-to-live: 1d
time-to-live
:
2000
#写入redis时是否使用键前缀。
use-key-prefix
:
true
key-prefix
:
spring-cache_
#mybatis
mybatis-plus
:
mapper-locations
:
classpath*:/mapper/**/*Dao.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage
:
com.esv.datacenter.cc.entity;com.esv.datacenter.cc.dto;com.esv.datacenter.cc.module.*.entity;com.esv.datacenter.cc.module.*.dto
check-config-location
:
true
#原生配置
configuration
:
map-underscore-to-camel-case
:
true
cache-enabled
:
false
call-setters-on-nulls
:
true
jdbc-type-for-null
:
'
null'
global-config
:
banner
:
true
#数据库相关配置
db-config
:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type
:
AUTO
logic-delete-value
:
1
logic-not-delete-value
:
0
management
:
endpoints
:
web
:
exposure
:
# "*"开放所有监控端点,指定监控端点,用逗号分隔
include
:
health
base-path
:
/esvActuator
endpoint
:
health
:
show-details
:
always
feign
:
hystrix
:
enabled
:
true
hystrix
:
command
:
default
:
execution
:
timeout
:
enabled
:
true
isolation
:
thread
:
timeoutInMilliseconds
:
5000
ribbon
:
eager-load
:
enabled
:
true
clients
:
datacenter-base-service
jwt
:
generate
:
key
:
upms_hello_world_001
secret
:
key
:
upms_hello_world_101
auth
:
noCheck
:
URL
:
/account/loginByAccountPwd,/account/checkToken
#api权限校验开关:true-校验、false-不校验
api
:
check
:
switch
:
true
#web端token存活时间,单位小时
token
:
live
:
time
:
web
:
12
app
:
prop
:
super-admin-role-id
:
1
cache
:
names
:
-
key
:
datacenter-cc::apiAuthority
timeout
:
600
-
key
:
datacenter-cc::userInfo
timeout
:
2592000
# 30天
-
key
:
datacenter-cc::systemByCode
timeout
:
2592000
\ No newline at end of file
src/main/resources/application-dev.yml
View file @
3ca37f01
...
...
@@ -12,7 +12,7 @@ spring:
max-wait
:
60000
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1
FROM DUAL
validation-query
:
SELECT
1
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
...
...
src/main/resources/application-local.yml
View file @
3ca37f01
...
...
@@ -12,7 +12,7 @@ spring:
max-wait
:
60000
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1
FROM DUAL
validation-query
:
SELECT
1
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
...
...
src/main/resources/application-test.yml
View file @
3ca37f01
...
...
@@ -12,7 +12,7 @@ spring:
max-wait
:
60000
time-between-eviction-runs-millis
:
60000
min-evictable-idle-time-millis
:
300000
validation-query
:
SELECT 1
FROM DUAL
validation-query
:
SELECT
1
test-while-idle
:
true
test-on-borrow
:
false
test-on-return
:
false
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment