mirror of https://gitee.com/maxjhandsome/pig
优化hystrix 线程隔离TTL取值为空问题
This commit is contained in:
parent
0a73ba0b23
commit
348c6e3530
|
@ -90,6 +90,13 @@
|
|||
<artifactId>fastdfs-spring-boot-starter</artifactId>
|
||||
<version>${fastdfs.version}</version>
|
||||
</dependency>
|
||||
<!-- TTL -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>${ttl.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.github.pig.common.util;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -17,9 +19,9 @@ import java.util.List;
|
|||
* @date 2017/11/20
|
||||
* 用户相关工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class UserUtils {
|
||||
private static Logger logger = LoggerFactory.getLogger(UserUtils.class);
|
||||
private static final ThreadLocal<String> THREAD_LOCAL_USER = new ThreadLocal<>();
|
||||
private static final ThreadLocal<String> THREAD_LOCAL_USER = new TransmittableThreadLocal<>();
|
||||
private static final String KEY_USER = "user";
|
||||
|
||||
|
||||
|
@ -44,7 +46,7 @@ public class UserUtils {
|
|||
Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
|
||||
username = claims.get("user_name").toString();
|
||||
} catch (Exception ex) {
|
||||
logger.error("用户名解析异常,token:{},key:{}", token, key);
|
||||
log.error("用户名解析异常,token:{},key:{}", token, key);
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ public class UserUtils {
|
|||
Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody();
|
||||
username = claims.get("user_name").toString();
|
||||
} catch (Exception ex) {
|
||||
logger.error("用户名解析异常,token:{},key:{}", token, key);
|
||||
log.error("用户名解析异常,token:{},key:{}", token, key);
|
||||
}
|
||||
return username;
|
||||
}
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -38,6 +38,7 @@
|
|||
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
|
||||
<swagger2.version>2.8.0</swagger2.version>
|
||||
<fastdfs.version>0.2.0</fastdfs.version>
|
||||
<ttl.version>2.2.0</ttl.version>
|
||||
<sharding-jdbc-core-spring-boot-starter.version>2.0.1</sharding-jdbc-core-spring-boot-starter.version>
|
||||
<velocity-engine-core.version>2.0</velocity-engine-core.version>
|
||||
<qiniu.version>[7.2.0, 7.2.99]</qiniu.version>
|
||||
|
|
Loading…
Reference in New Issue