Commit a1ba4041 by 刘宇峰

Merge remote-tracking branch 'origin/master'

2 parents 77d6d894 bdcbb08c
Showing 152 changed files with 2058 additions and 932 deletions
......@@ -6,6 +6,7 @@
<groupId>com.glsx</groupId>
<artifactId>rest-admin-framework</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath/>
</parent>
<artifactId>glsx-archetype-parent</artifactId>
......@@ -15,51 +16,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
<rest-admin-framework.version>2.0.0-SNAPSHOT</rest-admin-framework.version>
<!-- <repo.internal.snapshots.url>https://repo1.maven.org/maven2</repo.internal.snapshots.url>-->
<!-- <repo.internal.releases.url>https://repo1.maven.org/maven2</repo.internal.releases.url>-->
<!-- <repo.proxy.url>https://repo1.maven.org/maven2</repo.proxy.url>-->
<!-- <repo.external.url>https://repo1.maven.org/maven2</repo.external.url>-->
<local.nexus.snapshots.url>http://192.168.3.233/nexus/content/repositories/snapshots/</local.nexus.snapshots.url>
<local.nexus.releases.url>http://192.168.3.233/nexus/content/repositories/releases/</local.nexus.releases.url>
</properties>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--rest-admin-framework-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-framework-dependencies</artifactId>
<version>${rest-admin-framework.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
......
......@@ -47,56 +47,11 @@
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<!-- 一个命令更新版本,mvn versions:set -DnewVersion=1.2-SNAPSHOT -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -47,11 +47,11 @@
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- dubbo api -->
<!-- <dependency>-->
<!-- <groupId>cn.com.glsx.scrm</groupId>-->
<!-- <artifactId>rpc-scrm-proxy-api</artifactId>-->
<!-- <version>3.7.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>cn.com.glsx.scrm</groupId>
<artifactId>rpc-scrm-proxy-api</artifactId>
<version>3.7.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
......
......@@ -22,10 +22,8 @@ import static java.util.TimeZone.getTimeZone;
@EnableDubbo
@EnableRestAdmin
@EnableDiscoveryClient
@EnableTransactionManagement
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@EnableFeignClients(basePackages = {"cn.com.glsx.*.api"})
@SpringBootApplication(scanBasePackages = {"cn.com.glsx.*"})
@SpringBootApplication
public class Application {
public static void main(String[] args) {
......
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.scrm.proxy.model.ScreenshotRequest;
import cn.com.glsx.scrm.proxy.model.ScreenshotResponse;
import cn.com.glsx.scrm.proxy.remote.ScreenshotRemote;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class DubboDemoService {
// @DubboReference
// private ScreenshotRemote screenshotRemote;
@DubboReference
private ScreenshotRemote screenshotRemote;
public String screenshot(String url) {
// RpcResponse<ScreenshotResponse> response = screenshotRemote.screenshot(ScreenshotRequest.builder().url(url).build());
// return response.getResult().getUrl();
return "";
RpcResponse<ScreenshotResponse> response = screenshotRemote.screenshot(ScreenshotRequest.builder().url(url).build());
return response.getResult().getUrl();
}
}
......@@ -12,7 +12,7 @@ import com.glsx.plat.exception.ResultException;
import com.glsx.plat.exception.SystemMessage;
import com.glsx.plat.jwt.base.ComJwtUser;
import com.glsx.plat.jwt.util.JwtUtils;
import com.glsx.plat.web.utils.SessionUtils;
import com.glsx.plat.common.utils.SessionUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders;
......
......@@ -29,7 +29,6 @@
<groupId>com.glsx</groupId>
<artifactId>rest-admin-core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- feign -->
......@@ -37,7 +36,6 @@
<groupId>com.glsx</groupId>
<artifactId>rest-admin-feign</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!--oauth2认证-->
......
......@@ -21,20 +21,14 @@
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
<version>1.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- spring security -->
<dependency>
......@@ -45,7 +39,6 @@
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.1.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
......
......@@ -21,14 +21,10 @@
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
<version>1.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- spring security -->
......
......@@ -9,7 +9,7 @@
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>glsx-rest-admin-gateway-server</artifactId>
<artifactId>rest-admin-gateway-archetype</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -2,6 +2,7 @@ package com.glsx.plat.gateway.exception;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
......@@ -9,6 +10,7 @@ import org.springframework.web.reactive.function.server.ServerRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* @author payu
......@@ -18,11 +20,11 @@ import java.util.Map;
public class GlobalErrorAttributes extends DefaultErrorAttributes {
@Override
public Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
//简单返回
if (!includeStackTrace) return assembleError(request);
if (Objects.isNull(options)) return assembleError(request);
Map<String, Object> map = super.getErrorAttributes(request, includeStackTrace);
Map<String, Object> map = super.getErrorAttributes(request, options);
if (getError(request) instanceof GlobalException) {
GlobalException ex = (GlobalException) getError(request);
map.put(R.MSG_KEY, ex.getMessage());
......
package com.glsx.plat.gateway.exception;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler;
import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.context.ApplicationContext;
......@@ -24,7 +24,7 @@ public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHan
public GlobalErrorWebExceptionHandler(GlobalErrorAttributes g, ApplicationContext applicationContext,
ServerCodecConfigurer serverCodecConfigurer) {
super(g, new ResourceProperties(), applicationContext);
super(g, new WebProperties.Resources(), applicationContext);
super.setMessageWriters(serverCodecConfigurer.getWriters());
super.setMessageReaders(serverCodecConfigurer.getReaders());
}
......
......@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;
/**
* @author payu
......@@ -36,7 +37,7 @@ import java.util.Arrays;
@RefreshScope
public class AuthGlobalFilter implements GlobalFilter, Ordered {
@Value("${auth.skip.urls}")
@Value("${auth.skip.urls:#{null}}")
private String[] skipAuthUrls;
@Autowired
......@@ -57,7 +58,7 @@ public class AuthGlobalFilter implements GlobalFilter, Ordered {
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String url = exchange.getRequest().getURI().getPath();
//跳过不需要验证的路径
if (Arrays.asList(skipAuthUrls).contains(url)) {
if (!Objects.isNull(skipAuthUrls) && Arrays.asList(skipAuthUrls).contains(url)) {
return chain.filter(exchange);
}
......
spring.application.name=rest-admin-gateway
logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
spring.main.allow-bean-definition-overriding=true
#nacos config center
spring.cloud.nacos.config.server-addr=192.168.0.63:8868
spring.cloud.nacos.config.group=ARCHETYPE_GROUP
spring.cloud.nacos.config.prefix=${spring.application.name}
spring.profiles.active=dev
spring.cloud.nacos.config.file-extension=properties
#share config
spring.cloud.nacos.config.shared-configs[0].data-id=rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0].group=ARCHETYPE_GROUP
spring.cloud.nacos.config.shared-configs[0].refresh=true
\ No newline at end of file
spring.application.name=glsx-rest-admin-gateway
logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
spring.main.allow-bean-definition-overriding=true
#nacos配置中心
spring.cloud.nacos.config.server-addr=192.168.0.63:8848
spring.cloud.nacos.config.group=DEV_GROUP
spring.cloud.nacos.config.prefix=glsx-rest-admin-gateway
#spring.profiles.active=DEV
#spring.cloud.nacos.config.file-extension=properties
#微服务sentinel、zipkin、actuator等公共配置
spring.cloud.nacos.config.shared-configs[0].data-id=glsx-rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0].group=DEV_GROUP
spring.cloud.nacos.config.shared-configs[0].refresh=true
\ No newline at end of file
......@@ -9,15 +9,14 @@
<relativePath/>
</parent>
<artifactId>glsx-rest-admin-job-archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>rest-admin-job-archetype</artifactId>
<version>2.0.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<description>Microservice Scaffolding project for Spring Boot</description>
<modules>
<module>glsx-rest-admin-job</module>
<module>glsx-rest-admin-job-dao</module>
<module>rest-admin-job</module>
</modules>
<properties>
......@@ -25,42 +24,25 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
<rest-admin-framework.version>2.0.0-SNAPSHOT</rest-admin-framework.version>
<!-- <repo.internal.snapshots.url>https://repo1.maven.org/maven2</repo.internal.snapshots.url>-->
<!-- <repo.internal.releases.url>https://repo1.maven.org/maven2</repo.internal.releases.url>-->
<!-- <repo.proxy.url>https://repo1.maven.org/maven2</repo.proxy.url>-->
<!-- <repo.external.url>https://repo1.maven.org/maven2</repo.external.url>-->
<curator.version>2.12.0</curator.version>
</properties>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
</dependency>
<!--spring cloud alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
<!--rest-admin-framework-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-framework-dependencies</artifactId>
<version>${rest-admin-framework.version}</version>
<type>pom</type>
<scope>import</scope>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>${curator.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -80,48 +62,5 @@
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>glsx-rest-admin-job-archetype</artifactId>
<groupId>com.glsx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>glsx-rest-admin-job-dao</artifactId>
<dependencies>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--mybatis 逆向生成插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<!-- <phase>package</phase>-->
<phase>deploy</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!-- 自动生成的配置 -->
<configurationFile>src/main/resources/config/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package cn.com.glsx.admin.modules.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.glsx.plat.mybatis.base.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Accessors(chain = true)
@Data
@Entity
@Table(name = "t_user")
public class User extends BaseEntity {
/**
* 帐号
*/
@Column(name = "account", length = 64)
private String account;
/**
* 密码
*/
@JsonIgnore
@Column(name = "password", length = 128)
private String password;
/**
* 用户名
*/
@Column(name = "username", length = 64)
private String username;
/**
* (真实)姓名
*/
@Column(name = "realname", length = 64)
private String realname;
/**
* 手机号
*/
@Column(name = "phone", length = 20)
private String phone;
/**
* 头像链接
*/
@Column(name = "avatar", length = 150)
private String avatar;
/**
* 加密盐
*/
private String salt;
}
package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.User;
import cn.com.glsx.admin.modules.model.UserSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface UserMapper extends CommonBaseMapper<User> {
List<User> selectList(UserSearch search);
User selectByPhone(String phone);
void logicDeleteById(Long id);
}
\ No newline at end of file
package cn.com.glsx.admin.modules.model;
import cn.hutool.db.Page;
import lombok.Data;
/**
* @author payu
*/
@Data
public class UserSearch extends Page {
private String term;
}
//package com.glsx.vasp.modules.repository;
//
//import com.glsx.vasp.modules.entity.User;
//import java.io.Serializable;
//
///**
// * UserRepository JPA
// */
//public interface IUserRepository extends BaseRepository<User, Long>, Serializable {
//
// User findByUsername(String username);
//
//}
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- 配置生成器 -->
<generatorConfiguration>
<!--classPathEntry:数据库的JDBC驱动,换成你自己的驱动位置 可选 -->
<!-- <classPathEntry location="F://jdbc//mysql-connector-java-8.0.18.jar"/>-->
<!-- 一个数据库一个context -->
<context id="DB2Tables" targetRuntime="Mybatis3">
<!-- 自动识别数据库关键字,默认false,如果设置为true,根据SqlReservedWords中定义的关键字列表;一般保留默认值,遇到数据库关键字(Java关键字),使用columnOverride覆盖 -->
<property name="autoDelimitKeywords" value="true"/>
<!-- 生成的Java文件的编码 -->
<property name="javaFileEncoding" value="utf-8"/>
<!-- beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号; -->
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 格式化java代码 -->
<property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
<!-- 格式化XML代码 -->
<property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!-- 配置 tk.mybatis 插件 -->
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.glsx.plat.mybatis.mapper.CommonBaseMapper"/>
</plugin>
<!--配置生成注释信息,最多配置一个 -->
<commentGenerator>
<!-- 阻止生成注释包含时间戳 默认为false -->
<property name="suppressDate" value="true"/>
<!-- 注释是否添加数据库表的备注信息 默认为false -->
<property name="addRemarkComments" value="true"/>
</commentGenerator>
<!-- jdbc连接-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.3.222:3307/newgps?serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"
userId="root"
password="Msd^*$@online">
<!--防止生成其他库同名表-->
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="cn.com.glsx.admin.modules.entity" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值去掉前后空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成mapper.xml文件存放地址 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成接口dao type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator targetPackage="cn.com.glsx.admin.modules.mapper" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="smart_devide_status" domainObjectName="DeviceStatus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.vasp.modules.mapper.UserMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.vasp.modules.entity.User">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="wx_openid" jdbcType="VARCHAR" property="wxOpenid"/>
<result column="mini_openid" jdbcType="VARCHAR" property="miniOpenid"/>
<result column="enable_status" jdbcType="TINYINT" property="enableStatus"/>
<result column="delete_status" jdbcType="TINYINT" property="deleteStatus"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
</resultMap>
<select id="selectList" resultMap="BaseResultMap">
select * from t_user
</select>
<select id="selectByPhone" parameterType="java.lang.String" resultMap="BaseResultMap">
select * from t_user where phone = #{phone}
</select>
<update id="logicDeleteById" parameterType="java.lang.Long">
update t_user set delete_status = -1 where id = #{id}
</update>
</mapper>
\ No newline at end of file
......@@ -11,37 +11,30 @@
<packaging>war</packaging>
<description>Microservice Scaffolding Project Base on Spring Cloud</description>
<artifactId>glsx-rest-admin-job</artifactId>
<artifactId>rest-admin-job</artifactId>
<dependencies>
<!-- 运行环境上下文 -->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-context</artifactId>
<exclusions>
<exclusion>
<artifactId>checker-qual</artifactId>
<groupId>org.checkerframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 接入微服务组件联盟 配置、注册、网关、链路、监控等 ,单体应用无需引入(logback-spring.xml与logstash相关内容需要注释掉)-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-alliance</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-elasticjob</artifactId>
</dependency>
<!-- dao示例 -->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-job-dao</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -3,9 +3,9 @@ package cn.com.glsx;
import com.glsx.plat.context.EnableRestAdmin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct;
......@@ -20,8 +20,7 @@ import static java.util.TimeZone.getTimeZone;
@EnableRestAdmin
@EnableDiscoveryClient
@EnableTransactionManagement
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@SpringBootApplication(scanBasePackages = {"cn.com.glsx"})
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class Application {
public static void main(String[] args) {
......
......@@ -11,8 +11,6 @@ import com.glsx.plat.core.constant.BasicConstants;
*/
public final class Constants extends BasicConstants {
public final static String SERVER_NAME = "glsx_rest_admin";
public final static String SERVER_NAME = "rest-admin-job";
}
package cn.com.glsx.scheduler.common.exception;
import com.glsx.plat.exception.SystemMessage;
import lombok.Getter;
import lombok.Setter;
/**
* @author payu
*/
@Setter
@Getter
public class AdminException extends RuntimeException {
private int errorCode;
public AdminException() {
}
public AdminException(String message) {
super(message);
}
public AdminException(int errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
public AdminException of(SystemMessage message) {
return new AdminException(message.getCode(), message.getMsg());
}
public AdminException(Throwable cause) {
super(cause);
}
public AdminException(String message, Throwable cause) {
super(message, cause);
}
}
package cn.com.glsx.scheduler.common.exception;
import com.glsx.plat.core.web.R;
import com.glsx.plat.exception.ExceptionLevel;
import com.glsx.plat.exception.GlobalExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.BindingException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局异常处理
*
* @author payu
*/
@Slf4j
@RestControllerAdvice
public class AdminExceptionHandler extends GlobalExceptionHandler {
@ExceptionHandler(AdminException.class)
public R handleAdminException(AdminException e) {
return R.error(e.getMessage());
}
/**
* 引入Feign服务的话
*
* @param e
* @return
*/
// @ExceptionHandler(FeignException.class)
// public R handleFeignException(FeignException e) {
// return R.error(e.status(), e.getMessage());
// }
/**
* Mybatis BindingException
*
* @param e
* @return
*/
@ExceptionHandler(BindingException.class)
public R handleBindingException(BindingException e) {
return R.error(e.getMessage());
}
@Override
protected void saveException(Exception e, ExceptionLevel level) {
super.saveException(e, level);
}
}
package cn.com.glsx.scheduler.modules.job;
import cn.com.glsx.scheduler.modules.service.MySimpleJobService;
import cn.com.glsx.scheduler.modules.service.RestSimpleJobService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
......@@ -13,11 +13,11 @@ import java.util.Date;
@Slf4j
@Component
@ElasticSimpleJob(jobName = "MySimpleJob", cron = "0/30 * * * * ?")
public class MySimpleJob implements SimpleJob {
@ElasticSimpleJob("0/10 * * * * ?")
public class RestSimpleJob implements SimpleJob {
@Autowired
private MySimpleJobService simpleJobService;
private RestSimpleJobService simpleJobService;
@Override
public void execute(ShardingContext shardingContext) {
......@@ -34,7 +34,7 @@ public class MySimpleJob implements SimpleJob {
String normalDate = DateUtils.formatNormal(new Date());
log.info("---------------{}-开始----------------", normalDate);
simpleJobService.simpleJob("张三 " + normalDate);
log.info("---------------{}-结束--------------", normalDate);
log.info("---------------{}-结束--------------", DateUtils.formatNormal(new Date()));
}
}
package cn.com.glsx.scheduler.modules.service;
import cn.com.glsx.admin.modules.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author liuyf
* @date 2021年01月26日 下午2:37:40
*/
@Slf4j
@Service
public class MySimpleJobService {
@Autowired
private UserMapper userMapper;
public class RestSimpleJobService {
public void simpleJob(String name) {
try {
log.info("do something for job");
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("呼叫:" + name);
}
......
#项目名称
spring.application.name=glsx-rest-admin-job
spring.application.name=rest-admin-job
#日志路径(logback-spring.xml读取,不要加入配置中心)
logging.path=/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
#nacos配置中心
spring.cloud.nacos.config.server-addr=192.168.0.63:8848
spring.cloud.nacos.config.server-addr=192.168.0.63:8868
#nacos配置id,完整dataId=${spring.cloud.nacos.config.prefix}-${spring.profiles.active}.${file-extension(由新增配置时选的文件类型决定)}
#示例:http://192.168.0.63:8848/nacos/v1/cs/configs?dataId=glsx-rest-admin.properties&group=DEV_GROUP
spring.cloud.nacos.config.group=DEV_GROUP
spring.cloud.nacos.config.group=ARCHETYPE_GROUP
#配置prefix,默认值同${spring.application.name}
spring.cloud.nacos.config.prefix=${spring.application.name}
#配置开发环境
......@@ -18,11 +18,13 @@ spring.profiles.active=dev
spring.cloud.nacos.config.file-extension=properties
#微服务sentinel、zipkin、actuator等公共配置
spring.cloud.nacos.config.shared-configs[0].data-id=glsx-rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0].group=DEV_GROUP
spring.cloud.nacos.config.shared-configs[0].data-id=rest-microservice-share.properties
spring.cloud.nacos.config.shared-configs[0].group=ARCHETYPE_GROUP
spring.cloud.nacos.config.shared-configs[0].refresh=true
#数据库、redis等公共配置
spring.cloud.nacos.config.shared-configs[1].group=DEV_GROUP
spring.cloud.nacos.config.shared-configs[1].data-id=glsx-rest-admin-share.properties
spring.cloud.nacos.config.shared-configs[1].group=ARCHETYPE_GROUP
spring.cloud.nacos.config.shared-configs[1].data-id=rest-admin-share-dev.properties
spring.cloud.nacos.config.shared-configs[1].refresh=true
spring.main.allow-circular-references=true
\ No newline at end of file
package cn.com.glsx;
import cn.com.glsx.scheduler.modules.service.MySimpleJobService;
import cn.com.glsx.scheduler.modules.service.RestSimpleJobService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -12,11 +12,11 @@ import org.springframework.test.context.junit4.SpringRunner;
public class DemoApplicationTests {
@Autowired
private MySimpleJobService mySimpleJobService;
private RestSimpleJobService restSimpleJobService;
@Test
public void testJob() {
mySimpleJobService.simpleJob("13800138000");
restSimpleJobService.simpleJob("13800138000");
}
}
\ No newline at end of file
......@@ -10,60 +10,25 @@
<relativePath/>
</parent>
<artifactId>gslx-rest-admin-kafka-archetype</artifactId>
<artifactId>rest-admin-kafka-archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>glsx-rest-admin-kafka-producer</module>
<module>glsx-rest-admin-kafka-consumer</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
<rest-admin-framework.version>2.0.0-SNAPSHOT</rest-admin-framework.version>
<!-- <repo.internal.snapshots.url>https://repo1.maven.org/maven2</repo.internal.snapshots.url>-->
<!-- <repo.internal.releases.url>https://repo1.maven.org/maven2</repo.internal.releases.url>-->
<!-- <repo.proxy.url>https://repo1.maven.org/maven2</repo.proxy.url>-->
<!-- <repo.external.url>https://repo1.maven.org/maven2</repo.external.url>-->
</properties>
<dependencies>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud alibaba-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--rest-admin-framework-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-framework-dependencies</artifactId>
<version>${rest-admin-framework.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>rest-admin-kafka-producer</module>
<module>rest-admin-kafka-consumer</module>
</modules>
<build>
<resources>
......@@ -80,48 +45,5 @@
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
......@@ -3,14 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gslx-rest-admin-kafka-archetype</artifactId>
<artifactId>rest-admin-kafka-archetype</artifactId>
<groupId>com.glsx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>glsx-rest-admin-kafka-consumer</artifactId>
<artifactId>rest-admin-kafka-consumer</artifactId>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
......
......@@ -3,14 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gslx-rest-admin-kafka-archetype</artifactId>
<artifactId>rest-admin-kafka-archetype</artifactId>
<groupId>com.glsx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>glsx-rest-admin-kafka-producer</artifactId>
<artifactId>rest-admin-kafka-producer</artifactId>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
......
......@@ -77,7 +77,7 @@
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
......
......@@ -50,7 +50,7 @@
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<version>2.6.13</version>
</parent>
<groupId>com.glsx</groupId>
......@@ -23,16 +23,18 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<spring-cloud.version>Hoxton.SR12</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.9.RELEASE</spring-cloud-alibaba.version>
<!-- 版本说明:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E-->
<spring-cloud.version>2021.0.5</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
<revision>2.0.0-SNAPSHOT</revision>
<!-- 本地发布服务器 -->
<local.nexus.snapshots.url>http://127.0.0.1:8081/repository/maven-snapshots/</local.nexus.snapshots.url>
<local.nexus.releases.url>http://127.0.0.1:8081/repository/maven-releases/</local.nexus.releases.url>
<!-- <local.nexus.snapshots.url>http://127.0.0.1:8081/repository/maven-snapshots/</local.nexus.snapshots.url>-->
<!-- <local.nexus.releases.url>http://127.0.0.1:8081/repository/maven-releases/</local.nexus.releases.url>-->
<!-- <local.nexus.snapshots.url>http://192.168.3.233/nexus/content/repositories/snapshots/</local.nexus.snapshots.url>-->
<!-- <local.nexus.releases.url>http://192.168.3.233/nexus/content/repositories/releases/</local.nexus.releases.url>-->
<local.nexus.snapshots.url>http://192.168.3.233/nexus/content/repositories/snapshots/
</local.nexus.snapshots.url>
<local.nexus.releases.url>http://192.168.3.233/nexus/content/repositories/releases/</local.nexus.releases.url>
</properties>
<distributionManagement>
......
......@@ -16,8 +16,24 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<commons.lang.version>2.6</commons.lang.version>
<commons.fileupload.version>1.4</commons.fileupload.version>
<commons.io.version>2.11.0</commons.io.version>
<commons.codec.version>1.10</commons.codec.version>
<commons.lang3.version>3.12.0</commons.lang3.version>
<commons.collections4.version>4.4</commons.collections4.version>
<fastjson.version>1.2.76</fastjson.version>
<fastjson2.version>2.0.3</fastjson2.version>
<javassist.version>3.26.0-GA</javassist.version>
<guava.version>22.0</guava.version>
<hutool.version>5.7.20</hutool.version>
<pagehelper.version>5.3.0</pagehelper.version>
<jackson.version>2.13.3</jackson.version>
<joda.time.version>2.12.5</joda.time.version>
<persistence.version>1.0</persistence.version>
<pagehelper.boot.version>1.4.2</pagehelper.boot.version>
<jsqlparser.version>4.4</jsqlparser.version>
<mybatis.generator.version>1.4.1</mybatis.generator.version>
<org.mapstruct.version>1.5.2.Final</org.mapstruct.version>
</properties>
......@@ -26,19 +42,69 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.26.0-GA</version>
<version>${javassist.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis.generator.version}</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
......@@ -182,6 +248,11 @@
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis-generator</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-office</artifactId>
<version>${revision}</version>
</dependency>
......@@ -232,11 +303,6 @@
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-swagger2</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-swagger3</artifactId>
<version>${revision}</version>
</dependency>
......
......@@ -43,6 +43,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<curator.version>2.12.0</curator.version>
</properties>
<dependencyManagement>
......@@ -71,6 +72,22 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-client</artifactId>
<version>${curator.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -94,6 +111,7 @@
<module>rest-admin-redis</module>
<module>rest-admin-jpa</module>
<module>rest-admin-mybatis</module>
<module>rest-admin-mybatis-generator</module>
<module>rest-admin-datasource</module>
<module>rest-admin-dubbo</module>
......@@ -115,7 +133,6 @@
<module>rest-admin-elasticsearch</module>
<module>rest-admin-swagger2</module>
<module>rest-admin-swagger3</module>
<module>rest-admin-office</module>
......@@ -138,6 +155,10 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
......@@ -146,6 +167,10 @@
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......@@ -171,6 +196,80 @@
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<encoding>utf-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<phase>deploy</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- generator 工具配置文件的位置 此处必须配置 否则找不到该配置文件,maven build不成功-->
<configurationFile>src/test/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!--<scope>runtime</scope>-->
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-mybatis-generator</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<defaultGoal>compile</defaultGoal>
<resources>
<resource>
......
......@@ -31,17 +31,14 @@
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-common</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-redis</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
......
......@@ -24,14 +24,14 @@
<groupId>com.glsx</groupId>
<artifactId>rest-admin-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-sleuth</artifactId>
</dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-monitor</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-sleuth</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.glsx</groupId>-->
<!-- <artifactId>rest-admin-monitor</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-gateway-client</artifactId>
......
......@@ -21,7 +21,12 @@
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.1.1</version>
<exclusions>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
......
package com.glsx.plat.cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.glsx.plat.constant.CacheNameTimeConstant;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Configuration
public class CacheConfig {
@Bean
public CacheManager caffeineCacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
List<CaffeineCache> caches = new ArrayList<>();
caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_5SECS, Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build()));
caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_10SECS, Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build()));
caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_30SECS, Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build()));
cacheManager.setCaches(caches);
return cacheManager;
}
}
package com.glsx.plat.constant;
public interface CacheNameTimeConstant {
String CACHE_DEFAULT = "CACHE_DEFAULT";
String CACHE_10SECS = "CACHE_10SECS";
String CACHE_5SECS = "CACHE_5SECS";
String CACHE_30SECS = "CACHE_30SECS";
String CACHE_60SECS = "CACHE_60SECS";
String CACHE_10MINS = "CACHE_10MINS";
String CACHE_5MINS = "CACHE_5MINS";
String CACHE_30MINS = "CACHE_30MINS";
String CACHE_60MINS = "CACHE_60MINS";
String CACHE_12HOURS = "CACHE_12HOURS";
String CACHE_24HOURS = "CACHE_24HOURS";
String CACHE_3DAYS = "CACHE_3DAYS";
String CACHE_7DAYS = "CACHE_7DAYS";
String CACHE_30DAYS = "CACHE_30DAYS";
}
......@@ -18,9 +18,6 @@
<commons.codec.version>1.10</commons.codec.version>
<commons.lang3.version>3.12.0</commons.lang3.version>
<commons.collections4.version>4.4</commons.collections4.version>
<joda.time.version>2.10.14</joda.time.version>
<org.mapstruct.version>1.5.2.Final</org.mapstruct.version>
<fastjson.version>1.2.76</fastjson.version>
<fastjson2.version>2.0.3</fastjson2.version>
</properties>
......@@ -98,7 +95,6 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba.fastjson2</groupId>-->
......@@ -107,14 +103,8 @@
<!-- </dependency>-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
......@@ -126,12 +116,10 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
......
package com.glsx.plat.web.utils;
package com.glsx.plat.common.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......
package com.glsx.plat.common.utils;
import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
import java.io.UnsupportedEncodingException;
import java.security.Security;
import java.util.Arrays;
public class SM3Utils {
private static final String ENCODING = "UTF-8";
static {
Security.addProvider(new BouncyCastleProvider());
}
/**
* sm3 算法加密 *
*
* @param paramStr 待加密的参数字符串
* @param appKey 加密的密钥 appKey(接口访问秘钥 Key)
* @return 返回 SM3 加密后固定长度为 32 的 16 进制密内容文字符串
* @explain
*/
public static String encrypt(String paramStr, String appKey) {
//将返回的 hash 值转换成 16 进制字符串
String resultHexStr = "";
try {
//将字符串转换成 byte 数组
byte[] srcData = paramStr.getBytes(ENCODING);
//调用 hash()
byte[] resultHash = hmac(srcData, appKey.getBytes(ENCODING));
//将返回的 hash 值转换成 16 进制字符串
resultHexStr = ByteUtils.toHexString(resultHash);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return resultHexStr;
}
/**
* 通过密钥进行哈希
*
* @param appKey 加密的密钥 appKey 的 byte 数组
* @param srcData 被加密参数字符串的 byte 数组
* @return
*/
public static byte[] hmac(byte[] appKey, byte[] srcData) {
KeyParameter keyParameter = new KeyParameter(appKey);
SM3Digest digest = new SM3Digest();
HMac mac = new HMac(digest);
mac.init(keyParameter);
mac.update(srcData, 0, srcData.length);
byte[] result = new byte[mac.getMacSize()];
mac.doFinal(result, 0);
return result;
}
/**
* 判断待加密的原始数据与加密后的数据是否一致 *
*
* @param paramStr 待加密的参数字符串
* @param resultHexStr SM3 加密后固定长度为 32 的 16 进制密内容文字符串
* appKey
* 加密的密钥 appKey 的 byte 数组
* 校验结果
*/
public static boolean verify(String paramStr, String resultHexStr, String appKey) {
boolean flag = false;
try {
byte[] srcData = paramStr.getBytes(ENCODING);
byte[] sm3Hash = ByteUtils.fromHexString(resultHexStr);
byte[] newHash = hmac(srcData, appKey.getBytes(ENCODING));
if (Arrays.equals(newHash, sm3Hash)) {
flag = true;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return flag;
}
public static void main(String[] args) {
//待加密的待加密的参数字符串
String paramStr = "6bba9d97c252661067758b2b6f80e7c558e562b8";
//加密的密钥 appKey
String appKey = "RaOF35Kw";
//sm3 算法加密
String resultHexStr = SM3Utils.encrypt(paramStr, appKey);
System.out.println("待加密的待加密的参数字符串:" + paramStr);
System.out.println("SM3 加密后的密文字符串内容:" + resultHexStr);
System.out.println("校验结果:" + SM3Utils.verify(paramStr, resultHexStr, appKey));
}
}
\ No newline at end of file
package com.glsx.plat.web.utils;
package com.glsx.plat.common.utils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......
......@@ -3,6 +3,8 @@
*/
package com.glsx.plat.common.utils;
import org.springframework.util.AntPathMatcher;
import java.io.*;
import java.util.*;
......@@ -145,6 +147,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
/**
* 将null转空字符串
*
* @param origin
* @return
*/
......@@ -255,15 +258,41 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
return false;
}
/**
* 判断当前访问的url是否开头URI是在配置的忽略url列表中
*
* @param url
* @return
*/
public static boolean isMatchedStr(String[] skipAuthUrls, String url) {
if (StringUtils.isEmpty(url)) {
return false;
}
if (Objects.isNull(skipAuthUrls)) {
return false;
}
AntPathMatcher matcher = new AntPathMatcher();
for (String skipAuthUrl : skipAuthUrls) {
if (matcher.match(skipAuthUrl, url)) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
public static <T> T cast(Object obj) {
return (T) obj;
}
// public static void main(String[] args) throws UnsupportedEncodingException {
// System.out.println("中文a".getBytes("UTF-8").length); //7
// System.out.println(getStrLength("中文a")); //7
// System.out.println("中文a".length()); //3
//// System.out.println("中文a".getBytes("UTF-8").length); //7
//// System.out.println(getStrLength("中文a")); //7
//// System.out.println("中文a".length()); //3
//
// String[] skipAuthUrls = new String[]{"/login/check", "/api/**", "/**/v3/api-docs", "/open/api/access/queryAccessToken"};
// boolean flag = isMatchedStr(skipAuthUrls, "/platform-shopmall/v3/api-docs");
// System.out.println(flag);
// }
}
......@@ -43,7 +43,7 @@ public class NacosConfigLog {
dataId = prefix + "." + extension;
content = configService.getConfig(dataId, group, 5000);
}
log.info("- dataId {} config info\n{}", dataId, content);
log.info("{} -group {} dataId {} config info\n{}", serverAddr, group, dataId, content);
}
}
......@@ -2,7 +2,7 @@ package com.glsx.plat.context.aop;
import com.glsx.plat.common.annotation.NoResubmit;
import com.glsx.plat.core.web.R;
import com.glsx.plat.web.utils.IpUtils;
import com.glsx.plat.common.utils.IpUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
......
......@@ -5,7 +5,6 @@ import org.apache.commons.lang.time.DateUtils;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
......@@ -18,7 +17,7 @@ import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@EnableAsync
@Configuration
public class ThreadPoolConfig implements AsyncConfigurer {
public class ThreadPoolConfig {
DefaultRejectedExecutionHandler rejectedExecutionHandler = new DefaultRejectedExecutionHandler();
// 线程池维护线程的最少数量
......@@ -26,10 +25,9 @@ public class ThreadPoolConfig implements AsyncConfigurer {
//最大线程池大小
private int maxPoolSize = 150;
//队列容量,排队数
private int queueCapacity = 10000;
private int queueCapacity = 1000;
@Bean(name = "threadPoolTaskExecutor")
@Override
public ThreadPoolTaskExecutor getAsyncExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
//设置核心线程数
......@@ -41,7 +39,7 @@ public class ThreadPoolConfig implements AsyncConfigurer {
//设置线程活跃时间(秒) 最大允许空闲时间,超过时间并且当前池中线程数大于 corePoolSize 的时候会销毁
threadPoolTaskExecutor.setKeepAliveSeconds(60);
//设置默认线程名称
threadPoolTaskExecutor.setThreadNamePrefix("payu-");
threadPoolTaskExecutor.setThreadNamePrefix("plat-");
//设置拒绝策略
// threadPoolTaskExecutor.setRejectedExecutionHandler(rejectedExecutionHandler);
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
......@@ -56,7 +54,6 @@ public class ThreadPoolConfig implements AsyncConfigurer {
*
* @return
*/
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
AsyncUncaughtExceptionHandler asyncUncaughtExceptionHandler = (throwable, method, objects) -> {
log.error(method.getName() + " 执行异常", throwable);
......
......@@ -2,9 +2,14 @@ package com.glsx.plat.context.configuration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@ComponentScan({"com.glsx.plat"})
@ComponentScan({"com.glsx.plat", "cn.com.glsx.*"})
@EnableTransactionManagement
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class RestAdminAutoConfiguration {
}
}
\ No newline at end of file
package com.glsx.plat.context.utils;
import com.glsx.plat.exception.ValidateException;
import org.apache.commons.lang.StringUtils;
/**
* 断言工具类
*/
public class AssertUtil {
public static void isBlank(String str, String message) {
if (StringUtils.isBlank(str)) {
throw new ValidateException(message);
}
}
public static void isNull(Object object, String message) {
if (object == null) {
throw new ValidateException(message);
}
}
}
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
* <p>
* https://www.renren.io
* <p>
* 版权所有,侵权必究!
*/
package com.glsx.plat.context.utils.validator;
import com.glsx.plat.exception.ValidateException;
import org.apache.commons.lang.StringUtils;
/**
* 数据校验
*/
public abstract class AssertUtils {
public static void isBlank(String str, String message) {
if (StringUtils.isBlank(str)) {
throw new ValidateException(message);
}
}
public static void isNull(Object object, String message) {
if (object == null) {
throw new ValidateException(message);
}
}
}
......@@ -31,12 +31,22 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.20</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.glsx.plat.mybatis.base;
package com.glsx.plat.core.base;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.glsx.plat.core.enums.SysConstants;
......
package com.glsx.plat.core.enums;
public interface BaseEnum<E extends Enum<?>, T> {
public T getValue();
public String getDisplayName();
}
package com.glsx.plat.core.web;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class OpenApiResult<T> implements Serializable {
private static final String SUCCESS_DEFAULT_CODE = "00000";
private static final String FAILURE_DEFAULT_CODE = "44444";
private Boolean success;
private String code;
private String desc;
private T result;
private Long time;
public static <T> OpenApiResult<T> success(T result) {
return OpenApiResult.<T>builder()
.code(SUCCESS_DEFAULT_CODE)
.success(true)
.desc("成功")
.result(result)
.time(System.currentTimeMillis())
.build();
}
public static <T> OpenApiResult<T> failure(String code, String desc) {
return OpenApiResult.<T>builder()
.success(true)
.code(code)
.desc(desc)
.result(null)
.time(System.currentTimeMillis())
.build();
}
}
//package com.glsx.plat.datasource.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.support.http.StatViewServlet;
//import com.alibaba.druid.support.http.WebStatFilter;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.boot.web.servlet.ServletRegistrationBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.sql.DataSource;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Map;
//
//@Configuration
//public class DruidConfig {
//
// //加载application.yaml中的Druid配置
package com.glsx.plat.datasource.config;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DruidConfig {
//加载application.yaml中的Druid配置
// @ConfigurationProperties(prefix = "spring.datasource")
// @Bean
// public DataSource druid() {
// return new DruidDataSource();
// }
//
// //配置Druid的监控
// //1、配置一个管理后台的Servlet
// @Bean
......@@ -56,5 +44,31 @@
//
// return bean;
// }
// @Bean
// @ConfigurationProperties(prefix = "spring.datasource")
// public DataSource druidPrimary() {
// DruidDataSource druidDataSource = new DruidDataSource();
// List<Filter> filterList = new ArrayList<>();
// filterList.add(wallFilter());
// druidDataSource.setProxyFilters(filterList);
// return new DruidDataSource();
// }
//
//}
\ No newline at end of file
// @Bean
// public WallFilter wallFilter() {
// WallFilter wallFilter = new WallFilter();
// wallFilter.setConfig(wallConfig());
// return wallFilter;
// }
//
// @Bean
// public WallConfig wallConfig() {
// WallConfig config = new WallConfig();
// //允许一次执行多条语句
// config.setMultiStatementAllow(true);
// config.setNoneBaseStatementAllow(true);
// return config;
// }
}
\ No newline at end of file
......@@ -12,31 +12,49 @@
<artifactId>rest-admin-dubbo</artifactId>
<properties>
<curator.version>4.2.0</curator.version>
<curator.version>2.12.0</curator.version>
<dubbo.version>2.7.7</dubbo.version>
<zookeeper.version>3.4.6</zookeeper.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<!-- 4.0.0原生不兼容zk 3.4, 必须进行兼容性处理 -->
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.11</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<!--排除这个slf4j-log4j12-->
<exclusions>
<exclusion>
......@@ -45,15 +63,5 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.glsx.plat.dubbo.config;
import com.alibaba.spring.context.config.ConfigurationBeanBinder;
import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
import org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler;
import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.UnboundElementsSourceFilter;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import java.util.Map;
import static java.util.Arrays.asList;
import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from;
/**
* Spring Boot Relaxed {@link DubboConfigBinder} implementation
* see org.springframework.boot.context.properties.ConfigurationPropertiesBinder
*
* @since 2.7.0
*/
class BinderDubboConfigBinder implements ConfigurationBeanBinder {
@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields,
boolean ignoreInvalidFields, Object configurationBean) {
Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties));
// Converts ConfigurationPropertySources
Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources);
// Wrap Bindable from DubboConfig instance
Bindable bindable = Bindable.ofInstance(configurationBean);
Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources));
// Get BindHandler
BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields);
// Bind
binder.bind("", bindable, bindHandler);
}
private BindHandler getBindHandler(boolean ignoreUnknownFields,
boolean ignoreInvalidFields) {
BindHandler handler = BindHandler.DEFAULT;
if (ignoreInvalidFields) {
handler = new IgnoreErrorsBindHandler(handler);
}
if (!ignoreUnknownFields) {
UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
handler = new NoUnboundElementsBindHandler(handler, filter);
}
return handler;
}
}
package com.glsx.plat.dubbo.config;
import org.apache.dubbo.common.utils.Assert;
import org.springframework.core.env.PropertyResolver;
import org.springframework.lang.Nullable;
/**
* Delegating {@link PropertyResolver}
*
* @since 2.7.1
*/
class DelegatingPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
DelegatingPropertyResolver(PropertyResolver delegate) {
Assert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
@Nullable
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
@Nullable
public <T> T getProperty(String key, Class<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
}
\ No newline at end of file
package com.glsx.plat.dubbo.config;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import com.glsx.plat.dubbo.factory.ReferenceBuilderFactory;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceClassPostProcessor;
import org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBinding2AutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertyResolver;
import java.util.HashSet;
import java.util.Set;
import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX;
import static org.apache.dubbo.spring.boot.util.DubboUtils.PROPERTY_NAME_SEPARATOR;
/**
* Dubbo Auto {@link Configuration}
*
* @see DubboReference
* @see DubboService
* @see ServiceClassPostProcessor
* @see ReferenceAnnotationBeanPostProcessor
* @since 2.7.0
*/
//@Configuration
//@AutoConfigureAfter(DubboRelaxedBinding2AutoConfiguration.class)
//@EnableConfigurationProperties(DubboConfigurationProperties.class)
//@Import({DubboRelaxedBinding2AutoConfiguration.class})
public class DubboAutoConfiguration {
/**
* service类,服务提供者的BeanDefinitionRegistryPostProcessor类,用来解析 * @Service, @DubboService注解,生成Service的BeanDefinition类,放入spring容器,供spring容器生成Bean
* modify by alvin.zengqi
*
* @param propertyResolver
* @param properties
* @return
* @since 2.6.0
*/
@Bean
public ServiceClassPostProcessor serviceClassPostProcessor(PropertyResolver propertyResolver, DubboConfigurationProperties properties) {
Set<String> packagesToScan = new HashSet<>();
if (properties.getScan() != null && properties.getScan().getBasePackages() != null) {
packagesToScan = properties.getScan().getBasePackages();
}
// 兼容alibaba dubbo低版本scan
String scanPackage = propertyResolver.getProperty("dubbo.scan", String.class);
packagesToScan.add(scanPackage);
return new ServiceClassPostProcessor(packagesToScan);
}
/**
* 用来解析@Reference,@DubboReference 注解,消费者引用哪些服务,通过这个注解来进行引用 * 给标注这个@Reference,@DubboReference注解的属性赋值, 和@autowired的做法类似
* Creates {@link ReferenceAnnotationBeanPostProcessor} Bean if Absent
*
* @return {@link ReferenceAnnotationBeanPostProcessor}
*/
@ConditionalOnMissingBean
@Bean(name = ReferenceAnnotationBeanPostProcessor.BEAN_NAME)
public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor() {
return new ReferenceAnnotationBeanPostProcessor();
}
/**
* Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired}
*
* @param environment {@link Environment}
* @return alias bean for {@link Environment}
* @since 2.7.3
*/
@Bean
@Primary
public PropertyResolver primaryPropertyResolver(Environment environment) {
return environment;
}
public static final String DUBBO_LOG_TRACING_SUFFIX = "log.trace";
public static final String DUBBO_LOG_TRACING_PROPERTY = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + DUBBO_LOG_TRACING_SUFFIX;
/**
* 注册Reference构建工厂类
*
* @param env
* @return
*/
@Bean
public ReferenceBuilderFactory referenceBuilderFactory(ApplicationConfig config, PropertyResolver env) {
ReferenceBuilderFactory reference = new ReferenceBuilderFactory();
Boolean traceEnable = env.getProperty(DUBBO_LOG_TRACING_PROPERTY, Boolean.class);
if (null != traceEnable && !traceEnable) {
reference.setDefaultFilter("-logTrace");
}
return reference;
}
@Bean
@ConditionalOnProperty(prefix = DUBBO_PREFIX, name = DUBBO_LOG_TRACING_SUFFIX, havingValue = "false")
public ProviderConfig providerConfig(ApplicationConfig application, RegistryConfig registryConfig) {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setFilter("-logTrace");
providerConfig.setRegistry(registryConfig);
return providerConfig;
}
}
package com.glsx.plat.dubbo.config;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import org.apache.dubbo.config.*;
import org.apache.dubbo.config.spring.ConfigCenterBean;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.spring.boot.util.DubboUtils.*;
/**
* Dubbo {@link ConfigurationProperties Config Properties} only used to generate JSON metadata(non-public class)
*
* @since 2.7.1
*/
//@ConfigurationProperties(DUBBO_PREFIX)
class DubboConfigurationProperties {
@NestedConfigurationProperty
private Config config = new Config();
@NestedConfigurationProperty
private Scan scan = new Scan();
// Single Config Bindings
@NestedConfigurationProperty
private ApplicationConfig application = new ApplicationConfig();
@NestedConfigurationProperty
private ModuleConfig module = new ModuleConfig();
@NestedConfigurationProperty
private RegistryConfig registry = new RegistryConfig();
@NestedConfigurationProperty
private ProtocolConfig protocol = new ProtocolConfig();
@NestedConfigurationProperty
private MonitorConfig monitor = new MonitorConfig();
@NestedConfigurationProperty
private ProviderConfig provider = new ProviderConfig();
@NestedConfigurationProperty
private ConsumerConfig consumer = new ConsumerConfig();
@NestedConfigurationProperty
private ConfigCenterBean configCenter = new ConfigCenterBean();
@NestedConfigurationProperty
private MetadataReportConfig metadataReport = new MetadataReportConfig();
// Multiple Config Bindings
private Map<String, ModuleConfig> modules = new LinkedHashMap<>();
private Map<String, RegistryConfig> registries = new LinkedHashMap<>();
private Map<String, ProtocolConfig> protocols = new LinkedHashMap<>();
private Map<String, MonitorConfig> monitors = new LinkedHashMap<>();
private Map<String, ProviderConfig> providers = new LinkedHashMap<>();
private Map<String, ConsumerConfig> consumers = new LinkedHashMap<>();
private Map<String, ConfigCenterBean> configCenters = new LinkedHashMap<>();
private Map<String, MetadataReportConfig> metadataReports = new LinkedHashMap<>();
public Config getConfig() {
return config;
}
public void setConfig(Config config) {
this.config = config;
}
public Scan getScan() {
return scan;
}
public void setScan(Scan scan) {
this.scan = scan;
}
public ApplicationConfig getApplication() {
return application;
}
public void setApplication(ApplicationConfig application) {
this.application = application;
}
public ModuleConfig getModule() {
return module;
}
public void setModule(ModuleConfig module) {
this.module = module;
}
public RegistryConfig getRegistry() {
return registry;
}
public void setRegistry(RegistryConfig registry) {
this.registry = registry;
}
public ProtocolConfig getProtocol() {
return protocol;
}
public void setProtocol(ProtocolConfig protocol) {
this.protocol = protocol;
}
public MonitorConfig getMonitor() {
return monitor;
}
public void setMonitor(MonitorConfig monitor) {
this.monitor = monitor;
}
public ProviderConfig getProvider() {
return provider;
}
public void setProvider(ProviderConfig provider) {
this.provider = provider;
}
public ConsumerConfig getConsumer() {
return consumer;
}
public void setConsumer(ConsumerConfig consumer) {
this.consumer = consumer;
}
public ConfigCenterBean getConfigCenter() {
return configCenter;
}
public void setConfigCenter(ConfigCenterBean configCenter) {
this.configCenter = configCenter;
}
public MetadataReportConfig getMetadataReport() {
return metadataReport;
}
public void setMetadataReport(MetadataReportConfig metadataReport) {
this.metadataReport = metadataReport;
}
public Map<String, ModuleConfig> getModules() {
return modules;
}
public void setModules(Map<String, ModuleConfig> modules) {
this.modules = modules;
}
public Map<String, RegistryConfig> getRegistries() {
return registries;
}
public void setRegistries(Map<String, RegistryConfig> registries) {
this.registries = registries;
}
public Map<String, ProtocolConfig> getProtocols() {
return protocols;
}
public void setProtocols(Map<String, ProtocolConfig> protocols) {
this.protocols = protocols;
}
public Map<String, MonitorConfig> getMonitors() {
return monitors;
}
public void setMonitors(Map<String, MonitorConfig> monitors) {
this.monitors = monitors;
}
public Map<String, ProviderConfig> getProviders() {
return providers;
}
public void setProviders(Map<String, ProviderConfig> providers) {
this.providers = providers;
}
public Map<String, ConsumerConfig> getConsumers() {
return consumers;
}
public void setConsumers(Map<String, ConsumerConfig> consumers) {
this.consumers = consumers;
}
public Map<String, ConfigCenterBean> getConfigCenters() {
return configCenters;
}
public void setConfigCenters(Map<String, ConfigCenterBean> configCenters) {
this.configCenters = configCenters;
}
public Map<String, MetadataReportConfig> getMetadataReports() {
return metadataReports;
}
public void setMetadataReports(Map<String, MetadataReportConfig> metadataReports) {
this.metadataReports = metadataReports;
}
static class Config {
/**
* Indicates multiple properties binding from externalized configuration or not.
*/
private boolean multiple = DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE;
/**
* The property name of override Dubbo config
*/
private boolean override = DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE;
public boolean isOverride() {
return override;
}
public void setOverride(boolean override) {
this.override = override;
}
public boolean isMultiple() {
return multiple;
}
public void setMultiple(boolean multiple) {
this.multiple = multiple;
}
}
static class Scan {
/**
* The basePackages to scan , the multiple-value is delimited by comma
*
* @see EnableDubbo#scanBasePackages()
*/
private Set<String> basePackages = new LinkedHashSet<>();
public Set<String> getBasePackages() {
return basePackages;
}
public void setBasePackages(Set<String> basePackages) {
this.basePackages = basePackages;
}
}
}
package com.glsx.plat.dubbo.config;
import com.alibaba.spring.context.config.ConfigurationBeanBinder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.*;
import java.util.Map;
import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties;
import static org.apache.dubbo.spring.boot.util.DubboUtils.*;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;
/**
* Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 2.0
*
* @see DubboRelaxedBindingAutoConfiguration
* @since 2.7.0
*/
//@Configuration
//@ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder")
public class DubboRelaxedBinding2AutoConfiguration {
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) {
ConfigurableEnvironment propertyResolver = new AbstractEnvironment() {
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
Map<String, Object> dubboScanProperties = getSubProperties(environment.getPropertySources(), DUBBO_SCAN_PREFIX);
propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties));
}
};
return new DelegatingPropertyResolver(propertyResolver);
}
@ConditionalOnMissingBean(name = RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME, value = ConfigurationBeanBinder.class)
@Bean(RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME)
@Scope(scopeName = SCOPE_PROTOTYPE)
public ConfigurationBeanBinder relaxedDubboConfigBinder() {
return new BinderDubboConfigBinder();
}
}
package com.glsx.plat.dubbo.env;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.*;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import static org.apache.dubbo.spring.boot.util.DubboUtils.*;
/**
* The lowest precedence {@link EnvironmentPostProcessor} processes
* {@link SpringApplication#setDefaultProperties(Properties) Spring Boot default properties} for Dubbo
* as late as possible before {@link ConfigurableApplicationContext#refresh() application context refresh}.
*/
public class DubboDefaultPropertiesEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
/**
* The name of default {@link PropertySource} defined in SpringApplication#configurePropertySources method.
*/
public static final String PROPERTY_SOURCE_NAME = "defaultProperties";
/**
* The property name of "spring.main.allow-bean-definition-overriding".
* Please refer to: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#bean-overriding
*/
public static final String ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY = "spring.main.allow-bean-definition-overriding";
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
MutablePropertySources propertySources = environment.getPropertySources();
Map<String, Object> defaultProperties = createDefaultProperties(environment);
if (!CollectionUtils.isEmpty(defaultProperties)) {
addOrReplace(propertySources, defaultProperties);
}
}
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
private Map<String, Object> createDefaultProperties(ConfigurableEnvironment environment) {
Map<String, Object> defaultProperties = new HashMap<>();
setDubboApplicationNameProperty(environment, defaultProperties);
setDubboConfigMultipleProperty(defaultProperties);
setDubboApplicationQosEnableProperty(defaultProperties);
setAllowBeanDefinitionOverriding(defaultProperties);
return defaultProperties;
}
private void setDubboApplicationNameProperty(Environment environment, Map<String, Object> defaultProperties) {
String springApplicationName = environment.getProperty(SPRING_APPLICATION_NAME_PROPERTY);
if (StringUtils.hasLength(springApplicationName)
&& !environment.containsProperty(DUBBO_APPLICATION_NAME_PROPERTY)) {
defaultProperties.put(DUBBO_APPLICATION_NAME_PROPERTY, springApplicationName);
}
}
private void setDubboConfigMultipleProperty(Map<String, Object> defaultProperties) {
defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY, Boolean.TRUE.toString());
}
private void setDubboApplicationQosEnableProperty(Map<String, Object> defaultProperties) {
defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString());
}
/**
* Set {@link #ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY "spring.main.allow-bean-definition-overriding"} to be
* <code>true</code> as default.
*
* @param defaultProperties the default {@link Properties properties}
* @see #ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY
* @since 2.7.1
*/
private void setAllowBeanDefinitionOverriding(Map<String, Object> defaultProperties) {
defaultProperties.put(ALLOW_BEAN_DEFINITION_OVERRIDING_PROPERTY, Boolean.TRUE.toString());
}
/**
* Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)
*
* @param propertySources {@link MutablePropertySources}
* @param map Default Dubbo Properties
*/
private void addOrReplace(MutablePropertySources propertySources,
Map<String, Object> map) {
MapPropertySource target = null;
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
if (source instanceof MapPropertySource) {
target = (MapPropertySource) source;
for (String key : map.keySet()) {
if (!target.containsProperty(key)) {
target.getSource().put(key, map.get(key));
}
}
}
}
if (target == null) {
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map);
}
if (!propertySources.contains(PROPERTY_SOURCE_NAME)) {
propertySources.addLast(target);
}
}
}
package com.glsx.plat.dubbo.env;
import org.apache.dubbo.spring.boot.util.DubboUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.util.CollectionUtils;
import java.util.Map;
import java.util.SortedMap;
/**
* @author Alvin
* @version V1.0
* @Title: OreDubboPropertiesEnvironmentPostProcessor.java
* @Description: ore dubbo 配置处理
* @date 2020年8月28日 上午10:42:57
* @Company: didihu.com.cn
* @Copyright Copyright (c) 2020
*/
public class DubboPropertiesEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
/**
* Gets Logger After LoggingSystem configuration ready
*
* @see LoggingApplicationListener
*/
Logger logger = LoggerFactory.getLogger(getClass());
public static final String PROPERTY_SOURCE_NAME = "oreDubboProperties";
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
MutablePropertySources propertySources = environment.getPropertySources();
SortedMap<String, Object> dubboProperties = DubboUtils.filterDubboProperties(environment);
if (!CollectionUtils.isEmpty(dubboProperties)) {
addOrReplace(propertySources, dubboProperties);
}
if (logger.isInfoEnabled()) {
logger.info("Dubbo Config was overridden by ore externalized configuration {}", dubboProperties);
}
}
/**
* Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)
*
* @param propertySources {@link MutablePropertySources}
* @param map ore Dubbo Properties
*/
private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) {
MapPropertySource target = null;
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
if (source instanceof MapPropertySource) {
target = (MapPropertySource) source;
for (String key : map.keySet()) {
if (!target.containsProperty(key)) {
target.getSource().put(key, map.get(key));
}
}
}
}
if (target == null) {
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map);
}
if (!propertySources.contains(PROPERTY_SOURCE_NAME)) {
propertySources.addLast(target);
}
}
}
package com.glsx.plat.dubbo.factory;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.RegistryConfig;
import java.util.List;
public interface ReferenceBuilder<T> {
/**
* 可选参数,服务方法调用超时时间(毫秒)
* 缺省使用dubbo:consumer的timeout
*
* @param timeout
* @return this
*/
ReferenceBuilder<T> timeout(Integer timeout);
/**
* 可选参数,服务版本,与服务提供者的版本一致
*
* @param version
* @return this
*/
ReferenceBuilder<T> version(String version);
/**
* 可选参数,启动时检查提供者是否存在,true报错,false忽略
* 缺省使用dubbo:consumer的check
*
* @param check
* @return
*/
ReferenceBuilder<T> check(Boolean check);
/**
* 可选参数,点对点直连服务提供者地址,将绕过注册中心
*
* @param url
* @return
*/
ReferenceBuilder<T> url(String url);
/**
* 可选参数,服务分组,当一个接口有多个实现,可以用分组区分,必需和服务提供方一致
*
* @param group
* @return
*/
ReferenceBuilder<T> group(String group);
/**
* 可选参数,远程服务调用重试次数,不包括第一次调用,不需要重试请设为0
* 缺省使用dubbo:consumer的retries
*
* @param retries
* @return
*/
ReferenceBuilder<T> retries(Integer retries);
/**
* 可选参数,只调用指定协议的服务提供方,其它协议忽略。
*
* @param protocol
* @return
*/
ReferenceBuilder<T> protocol(String protocol);
/**
* 可选参数,对每个提供者的最大连接数,rmi、http、hessian等短连接协议表示限制连接数,dubbo等长连接协表示建立的长连接个数
* 缺省使用dubbo:consumer的connections
*
* @param connections
* @return
*/
ReferenceBuilder<T> connections(Integer connections);
/**
* 可选参数,负载均衡策略,可选值:random,roundrobin,leastactive,分别表示:随机,轮循,最少活跃调用
* 缺省使用dubbo:consumer的loadbalance
*
* @param loadbalance
* @return
*/
ReferenceBuilder<T> loadbalance(String loadbalance);
/**
* 可选参数,是否异步执行,不可靠异步,只是忽略返回值,不阻塞执行线程
* 缺省使用dubbo:consumer的async
*
* @param async
* @return
*/
ReferenceBuilder<T> async(Boolean async);
/**
* 可选参数,选择动态代理实现策略,可选:javassist, jdk。
* 缺省为:javassist
*
* @param proxy
* @return
*/
ReferenceBuilder<T> proxy(String proxy);
/**
* 可选参数,每服务消费者每服务每方法最大并发调用数。
* 缺省为:0
*
* @param actives
* @return
*/
ReferenceBuilder<T> actives(Integer actives);
/**
* 可选参数,客户端传输类型设置,如Dubbo协议的netty或mina。
*
* @param client
* @return
*/
ReferenceBuilder<T> client(String client);
/**
* 可选参数,方法级参数配置,如设置单个方法的超时时间、重试次数等
*
* @param method
* @return
* @Description:
* @author Alvin.zengqi
* @date 2018年1月27日 下午3:21:35
*/
ReferenceBuilder<T> method(MethodConfig method);
/**
* 可选参数,方法级参数配置,如设置多个方法的超时时间、重试次数等
*
* @param methods
* @return
* @Description:
* @author Alvin.zengqi
* @date 2018年1月27日 下午3:21:35
*/
ReferenceBuilder<T> methods(List<MethodConfig> methods);
/**
* 增加过滤器配置
*
* @param filterName
* @return
*/
ReferenceBuilder<T> filter(String filterName);
/**
* 增加注册中心配置
*
* @param registry
* @return
*/
ReferenceBuilder<T> registry(RegistryConfig registry);
/**
* 增加路由标签配置
*
* @param tagName
* @return
*/
ReferenceBuilder<T> tag(String tagName);
// 构造
T build();
}
package com.glsx.plat.dubbo.factory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import java.util.ArrayList;
import java.util.List;
public class ReferenceBuilderFactory {
@Autowired
private ApplicationConfig config;
@Autowired
private RegistryConfig registry;
@Autowired
private Environment env;
private String defaultFilter;
public <T> ReferenceBuilder<T> builder(Class<T> clazz) {
return new DefaultBuilder<T>(clazz);
}
private class DefaultBuilder<T> implements ReferenceBuilder<T> {
private ReferenceConfig<T> reference = new ReferenceConfig<T>();
DefaultBuilder(Class<T> clazz) {
config.setRegistry(registry);
reference.setInterface(clazz);
if (StringUtils.isNotEmpty(defaultFilter)) {
reference.setFilter(defaultFilter);
}
// 优先获取单个RPC服务直连地址,如:cn.com.glsx.***Remote.url=dubbo://127.0.0.1:20880
String url = env.getProperty(clazz.getName().concat(".url"));
if (StringUtils.isEmpty(url)) {
// 获取全局RPC服务直连地址,如:ore.dubbo.provider.url=dubbo://127.0.0.1:20880
url = env.getProperty("dubbo.provider.url");
}
reference.setUrl(url);
}
@Override
public ReferenceBuilder<T> timeout(Integer timeout) {
reference.setTimeout(timeout);
return this;
}
@Override
public ReferenceBuilder<T> version(String version) {
reference.setVersion(version);
return this;
}
@Override
public ReferenceBuilder<T> check(Boolean check) {
reference.setCheck(check);
return this;
}
@Override
public ReferenceBuilder<T> url(String url) {
reference.setUrl(url);
return this;
}
@Override
public T build() {
return reference.get();
}
@Override
public ReferenceBuilder<T> group(String group) {
reference.setGroup(group);
return this;
}
@Override
public ReferenceBuilder<T> retries(Integer retries) {
reference.setRetries(retries);
return this;
}
@Override
public ReferenceBuilder<T> protocol(String protocol) {
reference.setProtocol(protocol);
return this;
}
@Override
public ReferenceBuilder<T> connections(Integer connections) {
reference.setConnections(connections);
return this;
}
@Override
public ReferenceBuilder<T> loadbalance(String loadbalance) {
reference.setLoadbalance(loadbalance);
return this;
}
@Override
public ReferenceBuilder<T> async(Boolean async) {
reference.setAsync(async);
return this;
}
@Override
public ReferenceBuilder<T> proxy(String proxy) {
reference.setProxy(proxy);
return this;
}
@Override
public ReferenceBuilder<T> actives(Integer actives) {
reference.setActives(actives);
return this;
}
@Override
public ReferenceBuilder<T> method(MethodConfig method) {
List<MethodConfig> methods = reference.getMethods();
if (methods == null) {
methods = new ArrayList<MethodConfig>();
}
methods.add(method);
return methods(methods);
}
@Override
public ReferenceBuilder<T> methods(List<MethodConfig> methods) {
reference.setMethods(methods);
return this;
}
@Override
public ReferenceBuilder<T> filter(String filterName) {
reference.setFilter(filterName);
return this;
}
@Override
public ReferenceBuilder<T> client(String client) {
reference.setClient(client);
return this;
}
@Override
public ReferenceBuilder<T> registry(RegistryConfig registry) {
reference.setRegistry(registry);
return this;
}
@Override
public ReferenceBuilder<T> tag(String tagName) {
reference.setTag(tagName);
return this;
}
}
public String getDefaultFilter() {
return defaultFilter;
}
public void setDefaultFilter(String defaultFilter) {
this.defaultFilter = defaultFilter;
}
}
......@@ -11,46 +11,59 @@
<artifactId>rest-admin-elasticjob</artifactId>
<properties>
<curator.version>2.12.0</curator.version>
<zookeeper.version>3.4.6</zookeeper.version>
</properties>
<dependencies>
<!-- 运行环境上下文 -->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-context</artifactId>
</dependency>
<dependency>
<groupId>com.github.kuhn-he</groupId>
<artifactId>elastic-job-lite-spring-boot-starter</artifactId>
<version>2.1.53</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.shardingsphere.elasticjob</groupId>-->
<!-- <artifactId>elasticjob-lite-spring-boot-starter</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- zookeeper 分布式锁、注意zookeeper版本 版本限制-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.10.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
......
package com.glsx.plat.job.config;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,14 +26,14 @@ public class ElasticJobConfig {
* @param shardingTotalCount
* @param shardingItemParameters
*/
public void addSimpleJobScheduler(final Class<? extends SimpleJob> jobClass,
final String cron,
final int shardingTotalCount,
final String shardingItemParameters) {
JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder(jobClass.getName(), cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).jobParameter("job参数").build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig, jobClass.getCanonicalName());
JobScheduler jobScheduler = new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(simpleJobConfig).build());
jobScheduler.init();
}
// public void addSimpleJobScheduler(final Class<? extends SimpleJob> jobClass,
// final String cron,
// final int shardingTotalCount,
// final String shardingItemParameters) {
// JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder(jobClass.getName(), cron, shardingTotalCount).shardingItemParameters(shardingItemParameters).jobParameter("job参数").build();
// SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig, jobClass.getCanonicalName());
// JobScheduler jobScheduler = new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(simpleJobConfig).build());
// jobScheduler.init();
// }
}
\ No newline at end of file
//package com.glsx.plat.job.config;
//
//import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
//import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
//import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
////@Configuration
//public class ZookepeerConfig {
//
// //zookeeper链接字符串 localhost:2181
// private String ZOOKEEPER_CONNECTION_STRING = "localhost:2181";
// //定时任务命名空间
// private String JOB_NAMESPACE = "elastic-job-boot-java";
//
// //zk的配置及创建注册中心
// @Bean(initMethod = "init")
// public CoordinatorRegistryCenter setUpRegistryCenter(@Value("${elaticjob.zookeeper.server-lists}") final String serverList, @Value("${elaticjob.zookeeper.namespace}") final String namespace) {
// //zk的配置
// ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(serverList, namespace);
// //设置zk超时时间
// zookeeperConfiguration.setSessionTimeoutMilliseconds(1000);
// //创建注册中心
// CoordinatorRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
// return zookeeperRegistryCenter;
// }
//
//}
//
//package org.apache.curator.framework.api;
//
///**
// * Licensed to the Apache Software Foundation (ASF) under one
// * or more contributor license agreements. See the NOTICE file
// * distributed with this work for additional information
// * regarding copyright ownership. The ASF licenses this file
// * to you 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
// * <p>
// * http://www.apache.org/licenses/LICENSE-2.0
// * <p>
// * 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.
// */
//
//import org.apache.zookeeper.CreateMode;
//
//public interface CreateBuilderMain extends
// BackgroundPathAndBytesable<String>,
// CreateModable<ACLBackgroundPathAndBytesable<String>>,
// ACLCreateModeBackgroundPathAndBytesable<String>,
// Compressible<CreateBackgroundModeStatACLable>,
// Statable<CreateProtectACLCreateModePathAndBytesable<String>> {
// /**
// * Causes any parent nodes to get created if they haven't already been
// *
// * @return this
// */
// public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded();
//
//// public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded();
//
// /**
// * Causes any parent nodes to get created using {@link CreateMode#CONTAINER} if they haven't already been.
// * IMPORTANT NOTE: container creation is a new feature in recent versions of ZooKeeper.
// * If the ZooKeeper version you're using does not support containers, the parent nodes
// * are created as ordinary PERSISTENT nodes.
// *
// * @return this
// */
// public ProtectACLCreateModeStatPathAndBytesable<String> creatingParentContainersIfNeeded();
//
// /**
// * @return this
// * @deprecated this has been generalized to support all create modes. Instead, use:
// * <pre>
// * client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)...
// * </pre>
// */
// @Deprecated
// public ACLPathAndBytesable<String> withProtectedEphemeralSequential();
//
// /**
// * <p>
// * Hat-tip to https://github.com/sbridges for pointing this out
// * </p>
// *
// * <p>
// * It turns out there is an edge case that exists when creating sequential-ephemeral
// * nodes. The creation can succeed on the server, but the server can crash before
// * the created node name is returned to the client. However, the ZK session is still
// * valid so the ephemeral node is not deleted. Thus, there is no way for the client to
// * determine what node was created for them.
// * </p>
// *
// * <p>
// * Even without sequential-ephemeral, however, the create can succeed on the sever
// * but the client (for various reasons) will not know it.
// * </p>
// *
// * <p>
// * Putting the create builder into protection mode works around this.
// * The name of the node that is created is prefixed with a GUID. If node creation fails
// * the normal retry mechanism will occur. On the retry, the parent path is first searched
// * for a node that has the GUID in it. If that node is found, it is assumed to be the lost
// * node that was successfully created on the first try and is returned to the caller.
// * </p>
// *
// * @return this
// */
// public ACLCreateModeStatBackgroundPathAndBytesable<String> withProtection();
//}
//
......@@ -41,10 +41,6 @@
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
......
package com.glsx.plat.exception;
import com.glsx.plat.core.web.R;
import com.netflix.client.ClientException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.MDC;
......@@ -186,12 +185,6 @@ public class GlobalRExceptionHandler {
return R.error(e.getCode(), e.getMsg());
}
@ExceptionHandler(ClientException.class)
public R handleClientException(ClientException e) {
saveException(e, ExceptionLevel.fatal);
return R.error(e.getErrorCode(), e.getErrorMessage());
}
/**
* 未识别异常
*
......
package com.glsx.plat.exception;
import com.glsx.plat.core.web.OpenApiResult;
public class OpenApiResultException extends RuntimeException {
protected OpenApiResult r;
protected static final int MIN_AUTO_CODE = 40000;
protected OpenApiResultException(OpenApiResultException parent) {
if (parent != null) {
this.r = parent.r;
}
}
/**
* 内部系统用,对外api接口不能使用随机错误码
*
* @param message
* @return
*/
public static OpenApiResultException create(String message) {
int value = (int) (MIN_AUTO_CODE + Math.round((Integer.MAX_VALUE - MIN_AUTO_CODE) * Math.random()));
return create(value, message);
}
/**
* 返回码为整型
*
* @param returnCode
* @param message
* @return
*/
public static OpenApiResultException create(int returnCode, String message) {
OpenApiResultException businessException = new OpenApiResultException(null);
businessException.r = OpenApiResult.failure(String.valueOf(returnCode), message);
return businessException;
}
/**
* 返回码可以为字符串型
*
* @param returnCode
* @param message
* @return
*/
public static OpenApiResultException create(String returnCode, String message) {
OpenApiResultException businessException = new OpenApiResultException(null);
businessException.r = OpenApiResult.failure(returnCode, message);
return businessException;
}
public static OpenApiResultException create(OpenApiResult r) {
OpenApiResultException businessException = new OpenApiResultException(null);
businessException.r = r;
return businessException;
}
@Override
public String getMessage() {
return r.getDesc();
}
public OpenApiResult getResultEntity() {
return r;
}
}
package com.glsx.plat.exception;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.Serializable;
/**
* @author payu
*/
@Setter
@Getter
@Slf4j
@Data
public class ServiceException extends RuntimeException implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -17,11 +17,15 @@ public class ServiceException extends RuntimeException implements Serializable {
private String msg;
private String code;
public ServiceException(String code, String msg) {
super(msg);
this.code = code;
this.msg = msg;
}
public static ServiceException create(String code, String msg) {
ServiceException serviceException = new ServiceException();
serviceException.setCode(code);
serviceException.setMsg(msg);
return serviceException;
log.error("Service RuntimeException {} {}", code, msg);
return new ServiceException(code, msg);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!