diff --git a/src/main/java/com/wang/config/redis/JedisConfig.java b/src/main/java/com/wang/config/redis/JedisConfig.java index 909638d..8aea0a3 100644 --- a/src/main/java/com/wang/config/redis/JedisConfig.java +++ b/src/main/java/com/wang/config/redis/JedisConfig.java @@ -23,7 +23,10 @@ @ConfigurationProperties(prefix = "redis") public class JedisConfig { - private static Logger logger = LoggerFactory.getLogger(JedisConfig.class); + /** + * LOGGER + */ + private static final Logger LOGGER = LoggerFactory.getLogger(JedisConfig.class); private String host; @@ -55,10 +58,10 @@ public JedisPool redisPoolFactory(){ jedisPoolConfig.setMinIdle(minIdle); // JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password); JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, null); - logger.info("初始化Redis连接池JedisPool成功!" + " Redis地址: " + host + ":" + port); + LOGGER.info("初始化Redis连接池JedisPool成功!地址: " + host + ":" + port); return jedisPool; } catch (Exception e) { - logger.error("初始化Redis连接池JedisPool异常:" + e.getMessage()); + LOGGER.error("初始化Redis连接池JedisPool异常:" + e.getMessage()); } return null; } diff --git a/src/main/java/com/wang/config/shiro/UserRealm.java b/src/main/java/com/wang/config/shiro/UserRealm.java index 94985e3..049ed61 100644 --- a/src/main/java/com/wang/config/shiro/UserRealm.java +++ b/src/main/java/com/wang/config/shiro/UserRealm.java @@ -19,8 +19,6 @@ import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,8 +32,6 @@ @Service public class UserRealm extends AuthorizingRealm { - private static final Logger LOGGER = LoggerFactory.getLogger(UserRealm.class); - private final UserMapper userMapper; private final RoleMapper roleMapper; private final PermissionMapper permissionMapper; diff --git a/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java b/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java index bc05a01..5aa521e 100644 --- a/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java +++ b/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java @@ -29,9 +29,9 @@ */ public class JwtFilter extends BasicHttpAuthenticationFilter { /** - * Logger + * LOGGER */ - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private static final Logger LOGGER = LoggerFactory.getLogger(JwtFilter.class); /** * 这里我们详细说明下为什么最终返回的都是true,即允许访问 @@ -170,8 +170,8 @@ private void response401(ServletRequest req, ServletResponse resp, String msg) { String data = JsonConvertUtil.objectToJson(new ResponseBean(HttpStatus.UNAUTHORIZED.value(), "无权访问(Unauthorized):" + msg, null)); out.append(data); } catch (IOException e) { - logger.error(e.getMessage()); - throw new CustomException("直接返回Response信息出现IOException异常"); + LOGGER.error("直接返回Response信息出现IOException异常:" + e.getMessage()); + throw new CustomException("直接返回Response信息出现IOException异常:" + e.getMessage()); } finally { if (out != null) { out.close(); diff --git a/src/main/java/com/wang/util/AesCipherUtil.java b/src/main/java/com/wang/util/AesCipherUtil.java index 9f98f71..33fa624 100644 --- a/src/main/java/com/wang/util/AesCipherUtil.java +++ b/src/main/java/com/wang/util/AesCipherUtil.java @@ -35,9 +35,9 @@ public void setEncryptAESKey(String encryptAESKey) { } /** - * logger + * LOGGER */ - private static final Logger logger = LoggerFactory.getLogger(AesCipherUtil.class); + private static final Logger LOGGER = LoggerFactory.getLogger(AesCipherUtil.class); /** * 加密 @@ -68,22 +68,22 @@ public static String enCrypto(String str) { // 先将二进制转换成16进制,再返回Bsae64加密后的String return Base64ConvertUtil.encode(HexConvertUtil.parseByte2HexStr(cipherByte)); } catch (NoSuchAlgorithmException e){ - logger.error(e.getMessage()); + LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (UnsupportedEncodingException e){ - logger.error(e.getMessage()); + LOGGER.error("Bsae64加密异常:" + e.getMessage()); throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage()); } catch (NoSuchPaddingException e){ - logger.error(e.getMessage()); + LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (InvalidKeyException e){ - logger.error(e.getMessage()); + LOGGER.error("初始化Cipher对象异常:" + e.getMessage()); throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage()); } catch (IllegalBlockSizeException e){ - logger.error(e.getMessage()); + LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage()); } catch (BadPaddingException e){ - logger.error(e.getMessage()); + LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage()); } } @@ -115,22 +115,22 @@ public static String deCrypto(String str) { byte[] cipherByte = c.doFinal(HexConvertUtil.parseHexStr2Byte(Base64ConvertUtil.decode(str))); return new String(cipherByte); } catch (NoSuchAlgorithmException e){ - logger.error(e.getMessage()); + LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (UnsupportedEncodingException e){ - logger.error(e.getMessage()); + LOGGER.error("Bsae64加密异常:" + e.getMessage()); throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage()); } catch (NoSuchPaddingException e){ - logger.error(e.getMessage()); + LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); } catch (InvalidKeyException e){ - logger.error(e.getMessage()); + LOGGER.error("初始化Cipher对象异常:" + e.getMessage()); throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage()); } catch (IllegalBlockSizeException e){ - logger.error(e.getMessage()); + LOGGER.error("解密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage()); } catch (BadPaddingException e){ - logger.error(e.getMessage()); + LOGGER.error("解密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage()); } } diff --git a/src/main/java/com/wang/util/JedisUtil.java b/src/main/java/com/wang/util/JedisUtil.java index b2cbf3d..ecc84e2 100644 --- a/src/main/java/com/wang/util/JedisUtil.java +++ b/src/main/java/com/wang/util/JedisUtil.java @@ -4,8 +4,6 @@ import com.wang.model.common.Constant; import com.wang.util.common.StringUtil; import com.wang.util.common.SerializableUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import redis.clients.jedis.Jedis; @@ -21,11 +19,6 @@ @Component public class JedisUtil { - /** - * Logger - */ - private static Logger logger = LoggerFactory.getLogger(JedisUtil.class); - /** * 静态注入JedisPool连接池 * 本来是正常注入JedisUtil,可以在Controller和Service层使用,但是重写Shiro的CustomCache无法注入JedisUtil diff --git a/src/main/java/com/wang/util/JwtUtil.java b/src/main/java/com/wang/util/JwtUtil.java index 1f922f0..a1d27b2 100644 --- a/src/main/java/com/wang/util/JwtUtil.java +++ b/src/main/java/com/wang/util/JwtUtil.java @@ -8,6 +8,8 @@ import com.wang.exception.CustomException; import com.wang.model.common.Constant; import com.wang.util.common.Base64ConvertUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -22,6 +24,11 @@ @Component public class JwtUtil { + /** + * LOGGER + */ + private static final Logger LOGGER = LoggerFactory.getLogger(JwtUtil.class); + /** * 过期时间改为从配置文件获取 */ @@ -59,8 +66,8 @@ public static boolean verify(String token) { DecodedJWT jwt = verifier.verify(token); return true; } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - throw new CustomException("JWTToken认证解密出现UnsupportedEncodingException异常"); + LOGGER.error("JWTToken认证解密出现UnsupportedEncodingException异常:" + e.getMessage()); + throw new CustomException("JWTToken认证解密出现UnsupportedEncodingException异常:" + e.getMessage()); } } @@ -78,8 +85,8 @@ public static String getClaim(String token, String claim) { // 只能输出String类型,如果是其他类型返回null return jwt.getClaim(claim).asString(); } catch (JWTDecodeException e) { - e.printStackTrace(); - throw new CustomException("解密Token中的公共信息出现JWTDecodeException异常"); + LOGGER.error("解密Token中的公共信息出现JWTDecodeException异常:" + e.getMessage()); + throw new CustomException("解密Token中的公共信息出现JWTDecodeException异常:" + e.getMessage()); } } @@ -104,7 +111,8 @@ public static String sign(String account, String currentTimeMillis) { .withExpiresAt(date) .sign(algorithm); } catch (UnsupportedEncodingException e) { - throw new CustomException("JWTToken加密出现UnsupportedEncodingException异常"); + LOGGER.error("JWTToken加密出现UnsupportedEncodingException异常:" + e.getMessage()); + throw new CustomException("JWTToken加密出现UnsupportedEncodingException异常:" + e.getMessage()); } } } diff --git a/src/main/java/com/wang/util/common/PropertiesUtil.java b/src/main/java/com/wang/util/common/PropertiesUtil.java index adcc364..2668de9 100644 --- a/src/main/java/com/wang/util/common/PropertiesUtil.java +++ b/src/main/java/com/wang/util/common/PropertiesUtil.java @@ -1,6 +1,8 @@ package com.wang.util.common; import com.wang.exception.CustomException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.IOException; @@ -15,6 +17,11 @@ */ public class PropertiesUtil { + /** + * LOGGER + */ + private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesUtil.class); + /** * PROP */ @@ -34,15 +41,16 @@ public static void readProperties(String fileName){ BufferedReader bf = new BufferedReader(new InputStreamReader(in)); PROP.load(bf); } catch (IOException e){ - e.printStackTrace(); + LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); + throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); } finally { try{ if(in != null){ in.close(); } }catch (IOException e){ - e.printStackTrace(); - throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常"); + LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); + throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); } } } diff --git a/src/main/java/com/wang/util/common/SerializableUtil.java b/src/main/java/com/wang/util/common/SerializableUtil.java index d99f162..aeb2180 100644 --- a/src/main/java/com/wang/util/common/SerializableUtil.java +++ b/src/main/java/com/wang/util/common/SerializableUtil.java @@ -1,6 +1,8 @@ package com.wang.util.common; import com.wang.exception.CustomException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; @@ -11,6 +13,11 @@ */ public class SerializableUtil { + /** + * LOGGER + */ + private static final Logger LOGGER = LoggerFactory.getLogger(SerializableUtil.class); + /** * 序列化 * @param object @@ -28,8 +35,8 @@ public static byte[] serializable(Object object) { byte[] bytes = baos.toByteArray(); return bytes; } catch (IOException e) { - e.printStackTrace(); - throw new CustomException("SerializableUtil工具类序列化出现IOException异常"); + LOGGER.error("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage()); + throw new CustomException("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage()); } finally { try { if(oos != null) { @@ -39,7 +46,8 @@ public static byte[] serializable(Object object) { baos.close(); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); + throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); } } } @@ -59,11 +67,11 @@ public static Object unserializable(byte[] bytes) { ois = new ObjectInputStream(bais); return ois.readObject(); } catch (ClassNotFoundException e) { - e.printStackTrace(); - throw new CustomException("SerializableUtil工具类反序列化出现ClassNotFoundException异常"); + LOGGER.error("SerializableUtil工具类反序列化出现ClassNotFoundException异常:" + e.getMessage()); + throw new CustomException("SerializableUtil工具类反序列化出现ClassNotFoundException异常:" + e.getMessage()); } catch (IOException e) { - e.printStackTrace(); - throw new CustomException("SerializableUtil工具类反序列化出现IOException异常"); + LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); + throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); } finally { try { if(ois != null) { @@ -73,7 +81,8 @@ public static Object unserializable(byte[] bytes) { bais.close(); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.error("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); + throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); } } }