Commit f248bc6a by 李传峰

对接3.x,集成,改造

parent ded17383
**Pcloud Common Pom 3.x** **Pcloud Common Pom 3.x**
* Upgrade Spring Boot to 2.x * Upgrade Spring Boot to 2.x
* Upgrade Spring Cloud to Hoxton.SR11 * Upgrade Spring Cloud to Hoxton.SR11
\ No newline at end of file
## 各环境不同版本打包命令
```sh
-Dreversion=3.1.0-SNAPSHOT
mvn clean install -Denforcer.skip=true -Dmaven.test.skip=true -U -Dreversion=指定版本号
```
\ No newline at end of file
...@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
...@@ -18,6 +19,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -18,6 +19,7 @@ import com.alibaba.fastjson.JSONObject;
import com.pcloud.common.exceptions.BizException; import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.Permission; import com.pcloud.common.permission.Permission;
import com.pcloud.common.utils.SessionUtil; import com.pcloud.common.utils.SessionUtil;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
/** /**
* *
...@@ -40,6 +42,12 @@ public class GlobalHandlerInterceptor implements HandlerInterceptor { ...@@ -40,6 +42,12 @@ public class GlobalHandlerInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
if (handler instanceof ResourceHttpRequestHandler
|| handler instanceof BasicErrorController) {
return true;
}
HandlerMethod handlerMethod = (HandlerMethod) handler; HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod(); Method method = handlerMethod.getMethod();
if (method.isAnnotationPresent(Permission.class)) { if (method.isAnnotationPresent(Permission.class)) {
...@@ -58,11 +66,9 @@ public class GlobalHandlerInterceptor implements HandlerInterceptor { ...@@ -58,11 +66,9 @@ public class GlobalHandlerInterceptor implements HandlerInterceptor {
} }
} }
} }
if (!flag) if (!flag) {
throw BizException.PERMISSION_NOT_FOUND; throw BizException.PERMISSION_NOT_FOUND;
LOGGER.info("【权限验证】调用--" + method.getName() + "--方法,token为-->" + token); }
} else {
LOGGER.info("【权限验证】调用--" + method.getName() + "--方法,不需要权限。");
} }
return true; return true;
} }
......
...@@ -4,9 +4,7 @@ import com.pcloud.universe.monitor.provider.MonitorInterceptor; ...@@ -4,9 +4,7 @@ import com.pcloud.universe.monitor.provider.MonitorInterceptor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.pcloud.common.core.interceptor.GlobalHandlerInterceptor;
/** /**
* *
...@@ -16,7 +14,7 @@ import com.pcloud.common.core.interceptor.GlobalHandlerInterceptor; ...@@ -16,7 +14,7 @@ import com.pcloud.common.core.interceptor.GlobalHandlerInterceptor;
* @版本:1.0 * @版本:1.0
*/ */
@Configuration @Configuration
public class GlobalWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter { public class GlobalWebMvcConfigurerAdapter implements WebMvcConfigurer {
@Value("${spring.application.name}") @Value("${spring.application.name}")
private String appCode; private String appCode;
......
...@@ -5,9 +5,8 @@ import com.netflix.loadbalancer.ILoadBalancer; ...@@ -5,9 +5,8 @@ import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAvoidanceRule; import com.netflix.loadbalancer.ZoneAvoidanceRule;
import com.pcloud.common.utils.cache.redis.JedisClusterUtils; import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -15,13 +14,10 @@ import java.util.List; ...@@ -15,13 +14,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import lombok.extern.slf4j.Slf4j;
/** /**
* 自定义灰度发布规则 2019-11-19 by david * 自定义灰度发布规则 2019-11-19 by david
*/ */
@Slf4j @Slf4j
@Service
public class GrayRule extends ZoneAvoidanceRule { public class GrayRule extends ZoneAvoidanceRule {
/** /**
......
...@@ -48,10 +48,6 @@ ...@@ -48,10 +48,6 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency> </dependency>
<dependency> <dependency>
...@@ -406,6 +402,11 @@ ...@@ -406,6 +402,11 @@
<version>5.3.2</version> <version>5.3.2</version>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-spring-context</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.pcloud.common.config;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.stereotype.Component;
@Component
public class NacosConfigServiceInstance {
private static ConfigService SERVICE;
@NacosInjected
public void setConfigService(ConfigService configService) throws NacosException {
if (SERVICE == null) {
SERVICE = configService;
}
PublicConfig.loadPublicSystem(configService);
}
public static ConfigService getInstance() {
return SERVICE;
}
}
...@@ -3,50 +3,94 @@ ...@@ -3,50 +3,94 @@
*/ */
package com.pcloud.common.config; package com.pcloud.common.config;
import java.util.Map; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.alibaba.nacos.spring.util.NacosUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import com.pcloud.common.utils.ResourceUtils; import java.util.HashMap;
import java.util.Map;
/** /**
* 环境配置基础类 * 环境配置基础类
* @author diseng * @author diseng
* *
*/ */
@Configuration
@NacosPropertySource(dataId = "public_user.properties")
public class PublicConfig { public class PublicConfig {
/**
* 系统文件配置 加载。 private static Logger LOGGER = LoggerFactory.getLogger(PublicConfig.class);
*/
public static Map<String, String> PUBLIC_USER = ResourceUtils.getResource("public_user").getMap();
/** /**
* 系统文件配置 加载。 * 系统文件配置 加载。
*/ */
public static Map<String, String> PUBLIC_SYSTEM = ResourceUtils.getResource("public_system").getMap(); @Value("${IS_DEV_STATUS}")
public void setIsDevStatus(Boolean v) {
IS_DEV_STATUS = v;
}
@Value("${PWD_TIMES_USE_KAPTCHA}")
public void setPwdTimesUseKaptcha(Integer v) {
PWD_TIMES_USE_KAPTCHA = v;
}
@Value("${IS_USE_KAPTCHA}")
public void setIsUseKaptcha(Boolean v) {
IS_USE_KAPTCHA = v;
}
@Value("${PWD_ERROR_LIMIT_TIME}")
public void setPwdErrorLimitTime(Integer v) {
PWD_ERROR_LIMIT_TIME = v;
}
@Value("${PWD_ERROR_LIMIT_TIMES}")
public void setPwdErrorLimitTimes(Integer v) {
PWD_ERROR_LIMIT_TIMES = v;
}
/** /**
* 密码错误限制次数 * 密码错误限制次数
*/ */
public final static Integer PWD_ERROR_LIMIT_TIMES = Integer.parseInt(PUBLIC_USER.get("PWD_ERROR_LIMIT_TIMES")); public static Integer PWD_ERROR_LIMIT_TIMES;
/** /**
* 密码错误限制时间(分钟) * 密码错误限制时间(分钟)
*/ */
public final static Integer PWD_ERROR_LIMIT_TIME = Integer.parseInt(PUBLIC_USER.get("PWD_ERROR_LIMIT_TIME")); public static Integer PWD_ERROR_LIMIT_TIME;
/** /**
* 门户是否使用验证码 配合密码错误次数值使用 * 门户是否使用验证码 配合密码错误次数值使用
*/ */
public final static boolean IS_USE_KAPTCHA = Boolean.parseBoolean(PUBLIC_USER.get("IS_USE_KAPTCHA")); public static boolean IS_USE_KAPTCHA;
/** /**
* 密码错误次数值 将 出现验证码,如果值为0 则永远不会出现验证码 * 密码错误次数值 将 出现验证码,如果值为0 则永远不会出现验证码
*/ */
public final static Integer PWD_TIMES_USE_KAPTCHA = Integer.parseInt(PUBLIC_USER.get("PWD_TIMES_USE_KAPTCHA")); public static Integer PWD_TIMES_USE_KAPTCHA;
/** /**
* 是否开发状态 * 是否开发状态
*/ */
public final static boolean IS_DEV_STATUS = Boolean.parseBoolean(PUBLIC_USER.get("IS_DEV_STATUS")); public static boolean IS_DEV_STATUS;
/**
* 系统文件配置 加载。
*/
public static Map<String, String> PUBLIC_SYSTEM = new HashMap<>();
public static void loadPublicSystem(ConfigService configService) throws NacosException {
String config = configService.getConfig("public_system.properties", Constants.DEFAULT_GROUP, Constants.RECV_WAIT_TIMEOUT);
Map<String, Object> p = NacosUtils.toProperties(config);
p.forEach((k, v) -> {
PUBLIC_SYSTEM.put(k, v.toString());
});
LOGGER.info("public system loaded completed, size={}", PUBLIC_SYSTEM.size());
}
} }
package com.pcloud.common.constant; package com.pcloud.common.constant;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.pcloud.common.utils.FileUtils; import com.pcloud.common.utils.FileUtils;
...@@ -15,7 +15,7 @@ import com.pcloud.common.utils.string.StringUtil; ...@@ -15,7 +15,7 @@ import com.pcloud.common.utils.string.StringUtil;
* @date:2018年6月25日,下午7:30:21 * @date:2018年6月25日,下午7:30:21
*/ */
@Component("aliyunConstant") @Component("aliyunConstant")
@PropertySource(value = { "classpath:aliyun.properties" }) @NacosPropertySource(dataId = "aliyun.properties")
public class AliyunConstant { public class AliyunConstant {
/** /**
......
package com.pcloud.common.constant; package com.pcloud.common.constant;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
* @Date: 2019/11/25 14:28 * @Date: 2019/11/25 14:28
*/ */
@Component("appLabelConstant") @Component("appLabelConstant")
@PropertySource(value = { "classpath:app_label.properties" }) @NacosPropertySource(dataId = "app_label.properties")
public class AppLabelConstant { public class AppLabelConstant {
public static final String GRADE1 = "一年级"; public static final String GRADE1 = "一年级";
......
...@@ -4,6 +4,8 @@ import java.util.HashSet; ...@@ -4,6 +4,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -27,7 +29,7 @@ import redis.clients.jedis.JedisCluster; ...@@ -27,7 +29,7 @@ import redis.clients.jedis.JedisCluster;
*/ */
@Configuration @Configuration
@EnableCaching @EnableCaching
@PropertySource(value = "classpath:redis.properties") @NacosPropertySource(dataId = "redis.properties")
public class JedisClusterConfig { public class JedisClusterConfig {
/** /**
...@@ -38,6 +40,9 @@ public class JedisClusterConfig { ...@@ -38,6 +40,9 @@ public class JedisClusterConfig {
@Value("${redis.cluster.host}") @Value("${redis.cluster.host}")
private String host; private String host;
@Value("${redis.cluster.password}")
private String password;
@Value("${redis.cluster.timeout}") @Value("${redis.cluster.timeout}")
private int timeout; private int timeout;
...@@ -75,6 +80,7 @@ public class JedisClusterConfig { ...@@ -75,6 +80,7 @@ public class JedisClusterConfig {
@Bean @Bean
public GenericObjectPoolConfig jedisPoolConfig() { public GenericObjectPoolConfig jedisPoolConfig() {
LOGGER.info("【redis】JedisPool注入成功,<START>"); LOGGER.info("【redis】JedisPool注入成功,<START>");
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(maxTotal); poolConfig.setMaxTotal(maxTotal);
poolConfig.setMinIdle(minIdle); poolConfig.setMinIdle(minIdle);
...@@ -90,8 +96,22 @@ public class JedisClusterConfig { ...@@ -90,8 +96,22 @@ public class JedisClusterConfig {
*/ */
@Bean @Bean
public JedisCluster JedisClusterFactory() { public JedisCluster JedisClusterFactory() {
LOGGER.info("【redis】JedisCluster创建,<START>"); LOGGER.info("【redis】JedisCluster创建,{},=>{}<=]", timeout, password);
return new JedisCluster(parseHostAndPort(), timeout, maxRedirections, jedisPoolConfig()); try {
JedisCluster jc = new JedisCluster(parseHostAndPort(), timeout, timeout, maxRedirections, StringUtils.trimToNull(password), jedisPoolConfig());
LOGGER.info("【redis】JedisCluster创建,echo={}", jc.echo("Echo Successfully."));
return jc;
} catch (Exception e) {
LOGGER.info("【redis】JedisCluster创建无密重试,{},=>{}<=],message={}", timeout, password, e.getMessage());
JedisCluster jc = new JedisCluster(parseHostAndPort(), timeout, maxRedirections, jedisPoolConfig());
LOGGER.info("【redis】JedisCluster创建无密重试,echo={}", jc.echo("Echo Successfully."));
return jc;
}
} }
/** /**
......
/*
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.netflix.feign;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
/**
* Annotation for interfaces declaring that a REST client with that interface should be
* created (e.g. for autowiring into another component). If ribbon is available it will be
* used to load balance the backend requests, and the load balancer can be configured
* using a <code>@RibbonClient</code> with the same name (i.e. value) as the feign client.
*
* @author Spencer Gibb
* @author Venil Noronha
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@org.springframework.cloud.openfeign.FeignClient
public @interface FeignClient {
/**
* The name of the service with optional protocol prefix. Synonym for {@link #name()
* name}. A name must be specified for all clients, whether or not a url is provided.
* Can be specified as property key, eg: ${propertyKey}.
*/
@AliasFor("name")
String value() default "";
/**
* The service id with optional protocol prefix. Synonym for {@link #value() value}.
*
* @deprecated use {@link #name() name} instead
*/
@Deprecated
String serviceId() default "";
/**
* The service id with optional protocol prefix. Synonym for {@link #value() value}.
*/
@AliasFor("value")
String name() default "";
/**
* Sets the <code>@Qualifier</code> value for the feign client.
*/
String qualifier() default "";
/**
* An absolute URL or resolvable hostname (the protocol is optional).
*/
String url() default "";
/**
* Whether 404s should be decoded instead of throwing FeignExceptions
*/
boolean decode404() default false;
/**
* A custom <code>@Configuration</code> for the feign client. Can contain override
* <code>@Bean</code> definition for the pieces that make up the client, for instance
* {@link feign.codec.Decoder}, {@link feign.codec.Encoder}, {@link feign.Contract}.
*
* @see FeignClientsConfiguration for the defaults
*/
Class<?>[] configuration() default {};
/**
* Fallback class for the specified Feign client interface. The fallback class must
* implement the interface annotated by this annotation and be a valid spring bean.
*/
Class<?> fallback() default void.class;
/**
* Define a fallback factory for the specified Feign client interface. The fallback
* factory must produce instances of fallback classes that implement the interface
* annotated by {@link FeignClient}. The fallback factory must be a valid spring
* bean.
*
* @see feign.hystrix.FallbackFactory for details.
*/
Class<?> fallbackFactory() default void.class;
/**
* Path prefix to be used by all method-level mappings. Can be used with or without
* <code>@RibbonClient</code>.
*/
String path() default "";
/**
* Whether to mark the feign proxy as a primary bean. Defaults to true.
*/
boolean primary() default true;
}
...@@ -83,7 +83,6 @@ ...@@ -83,7 +83,6 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>druid</artifactId> <artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment