11 changed files with 235 additions and 11 deletions
@ -0,0 +1,40 @@ |
|||||
|
//package com.epmet.jmreport.aop;
|
||||
|
//
|
||||
|
//import com.epmet.commons.tools.aspect.BaseRequestLogAspect;
|
||||
|
//import org.aspectj.lang.ProceedingJoinPoint;
|
||||
|
//import org.aspectj.lang.annotation.Around;
|
||||
|
//import org.aspectj.lang.annotation.Aspect;
|
||||
|
//import org.springframework.core.annotation.Order;
|
||||
|
//import org.springframework.stereotype.Component;
|
||||
|
//import org.springframework.web.context.request.RequestAttributes;
|
||||
|
//import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
//import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
//
|
||||
|
//import javax.servlet.http.HttpServletRequest;
|
||||
|
//
|
||||
|
///**
|
||||
|
// * 日志/异常处理切面实现,调用父类方法完成日志记录和异常处理。
|
||||
|
// */
|
||||
|
//@Aspect
|
||||
|
//@Component
|
||||
|
//@Order(0)
|
||||
|
//public class RequestLogAspect {
|
||||
|
//
|
||||
|
// @Override
|
||||
|
// @Around(value = "execution(* com...*Controller*.*(..)) ")
|
||||
|
// public Object proceed(ProceedingJoinPoint point) throws Throwable {
|
||||
|
// return super.proceed(point, getRequest());
|
||||
|
// }
|
||||
|
//
|
||||
|
// /**
|
||||
|
// * 获取Request对象
|
||||
|
// *
|
||||
|
// * @return
|
||||
|
// */
|
||||
|
// private HttpServletRequest getRequest() {
|
||||
|
// RequestAttributes ra = RequestContextHolder.getRequestAttributes();
|
||||
|
// ServletRequestAttributes sra = (ServletRequestAttributes) ra;
|
||||
|
// return sra.getRequest();
|
||||
|
// }
|
||||
|
//
|
||||
|
//}
|
@ -0,0 +1,54 @@ |
|||||
|
/** |
||||
|
* Copyright (c) 2018 人人开源 All rights reserved. |
||||
|
* |
||||
|
* https://www.renren.io
|
||||
|
* |
||||
|
* 版权所有,侵权必究! |
||||
|
*/ |
||||
|
|
||||
|
package com.epmet.jmreport.config.redis; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.parser.ParserConfig; |
||||
|
import com.alibaba.fastjson.serializer.SerializerFeature; |
||||
|
import com.alibaba.fastjson.util.IOUtils; |
||||
|
import org.springframework.data.redis.serializer.RedisSerializer; |
||||
|
import org.springframework.data.redis.serializer.SerializationException; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Redis序列化 |
||||
|
* |
||||
|
* @author Mark sunlightcs@gmail.com |
||||
|
* @since 1.0.0 |
||||
|
*/ |
||||
|
public class JsonRedisSerializer<T> implements RedisSerializer<T> { |
||||
|
private static ParserConfig defaultRedisConfig = new ParserConfig(); |
||||
|
static { |
||||
|
defaultRedisConfig.setAutoTypeSupport(true); |
||||
|
} |
||||
|
|
||||
|
private Class<T> type; |
||||
|
|
||||
|
public JsonRedisSerializer(Class<T> type) { |
||||
|
this.type = type; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public byte[] serialize(T t) throws SerializationException { |
||||
|
if (t == null) { |
||||
|
return new byte[0]; |
||||
|
} |
||||
|
return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(IOUtils.UTF8); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public T deserialize(byte[] bytes) throws SerializationException { |
||||
|
if (bytes == null || bytes.length <= 0) { |
||||
|
return null; |
||||
|
} |
||||
|
String str = new String(bytes, IOUtils.UTF8); |
||||
|
|
||||
|
return JSON.parseObject(str, type, defaultRedisConfig); |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.epmet.jmreport.config.redis; |
||||
|
|
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
|
import org.springframework.data.redis.core.RedisTemplate; |
||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* Redis配置 |
||||
|
* |
||||
|
* @author Mark sunlightcs@gmail.com |
||||
|
* @since 1.0.0 |
||||
|
*/ |
||||
|
@Configuration |
||||
|
public class RedisConfig { |
||||
|
@Resource |
||||
|
private RedisConnectionFactory factory; |
||||
|
|
||||
|
@Bean |
||||
|
public RedisTemplate<String, Object> redisTemplate() { |
||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); |
||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer()); |
||||
|
redisTemplate.setValueSerializer(new JsonRedisSerializer<>(Object.class)); |
||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer()); |
||||
|
redisTemplate.setHashValueSerializer(new JsonRedisSerializer<>(Object.class)); |
||||
|
redisTemplate.setConnectionFactory(factory); |
||||
|
return redisTemplate; |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
# 项目启动的时候,会根据环境,取这个配置 |
||||
|
mysql: |
||||
|
host: 192.168.1.140 |
||||
|
port: 3306 |
||||
|
db: epmet_jmreport |
||||
|
username: root |
||||
|
password: root |
||||
|
|
||||
|
nacos: |
||||
|
discovery: |
||||
|
server-addr: 192.168.1.140:8848 |
||||
|
namespace: 1fecc730-5e6e-464c-aae9-7567944e7936 |
||||
|
enabled: false |
||||
|
|
||||
|
spring: |
||||
|
redis: |
||||
|
host: 192.168.1.140 |
||||
|
port: 6379 |
||||
|
database: 0 |
||||
|
password: 123456 |
Loading…
Reference in new issue