init project
This commit is contained in:
commit
67c917562e
33
archetype-simple/.gitignore
vendored
Normal file
33
archetype-simple/.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# maven ignore
|
||||
target/
|
||||
*.jar
|
||||
*.war
|
||||
*.zip
|
||||
*.tar
|
||||
*.tar.gz
|
||||
|
||||
# eclipse ignore
|
||||
.settings/
|
||||
.project
|
||||
.classpath
|
||||
|
||||
# idea ignore
|
||||
.idea/
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
|
||||
# temp ignore
|
||||
logs/
|
||||
*.doc
|
||||
*.log
|
||||
*.cache
|
||||
*.diff
|
||||
*.patch
|
||||
*.tmp
|
||||
|
||||
# system ignore
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.class
|
||||
15
archetype-simple/README.md
Normal file
15
archetype-simple/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# archetype-simple
|
||||
|
||||
公司项目简单骨架
|
||||
|
||||
## xxx-api
|
||||
业务逻辑模块,包前缀标准为:``cn.axzo.xxx.service.api.`` 里面定义的接口直接给 xxx-client 中的 controller 调用,所有的业务逻辑都会被封装到它的实现类当中。业务 Controller 只会调用这个 Service 并不关注具体的业务实现细节。可以定义 request 包用于 service 接口的请求参数,可以定义 response 用于 service 接口的响应参数。
|
||||
|
||||
## xxx-api-impl
|
||||
业务逻辑实现模块,是 xxx-service-api 模块定义的接口的实现类接口,包前缀标准为:``cn.axzo.xxx.service.impl.``.它是聚合 xxx-manager 这个通用处理层的,它主要是集成数据库访问以及第三方接口的调用。它的作用是业务逻辑的编排。
|
||||
|
||||
## xxx-client
|
||||
请求处理模块,包前缀标准为:``cn.axzo.xxx.client.`` 里面可以定义 controller 包用于定义响应前端请求的控制器,config 包用于定义整个项目的配置(Redis 配置,Xxl Job 配置,Spring Web 统一异常配置,数据库配置等),interceptor 包用来定义 spring mvc 中的拦截器等。
|
||||
|
||||
## xxx-test:
|
||||
单元测试模块:所有模块的单元测试都可以放在这个模块里。
|
||||
21
archetype-simple/pom.xml
Normal file
21
archetype-simple/pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>cn.axzo.archetype</groupId>
|
||||
<artifactId>archetype-simple</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>archetype-simple</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archetype-descriptor
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
|
||||
name="demo-parent"
|
||||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modules>
|
||||
<module id="${rootArtifactId}-api" dir="__rootArtifactId__-api" name="${rootArtifactId}-api">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-api-impl" dir="__rootArtifactId__-api-impl" name="${rootArtifactId}-api-impl">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-client" dir="__rootArtifactId__-client" name="${rootArtifactId}-client">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-test" dir="__rootArtifactId__-test" name="${rootArtifactId}-test">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/test/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
</modules>
|
||||
</archetype-descriptor>
|
||||
@ -0,0 +1,96 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-api-impl</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.service.api;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ServiceTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-api</artifactId>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ServiceTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-client</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.client;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ClientTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||
<!--属性-->
|
||||
<property name="PROJECT_NAME" value="bcap"/>
|
||||
<!--日志路径-->
|
||||
<property name="LOG_PATH" value="logs"/>
|
||||
<!-- 日志最大的历史 30天 -->
|
||||
<property name="MAX_HISTORY" value="30"/>
|
||||
<!--默认日志输出模式-->
|
||||
<property name="LOG_PATTERN"
|
||||
value="[%date{yyyy-MM-dd HH:mm:ss:SSS}] [%level] [%thread] [%X{ctxLogId}] [axzo-bcap-service] [%class{36}#%M:%L] %msg%n"/>
|
||||
<!--环境名-->
|
||||
<contextName>${PROJECT_NAME}</contextName>
|
||||
|
||||
<!--错误日志-->
|
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_PATH}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/error/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>error</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/warn.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/warn/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>warn</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/info.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/info/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/debug/debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- ConsoleAppender 控制台输出日志 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender" addtivity="false">
|
||||
<encoder>
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>info</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- ConsoleAppender 控制台输出日志 -->
|
||||
<appender name="JSON_STDOUT" class="ch.qos.logback.core.ConsoleAppender" addtivity="false">
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
<fieldName>@timestamp</fieldName>
|
||||
<pattern>yyyy-MM-dd'T'HH:mm:ss.SSSx</pattern>
|
||||
<timeZone>GMT+8</timeZone>
|
||||
</timestamp>
|
||||
<pattern>
|
||||
<pattern>
|
||||
{
|
||||
<!--
|
||||
"@timestamp":"%date{ISO8601}",
|
||||
-->
|
||||
"app": "${appName}",
|
||||
"level": "%level",
|
||||
<!-- "trace": "%X{X-B3-TraceId:-}",
|
||||
"span": "%X{X-B3-SpanId:-}",
|
||||
"parent": "%X{X-B3-ParentSpanId:-}",-->
|
||||
"thread": "%thread",
|
||||
"class": "%logger{40}",
|
||||
"message":"%message",
|
||||
"m":"#asJson{%message}",
|
||||
"stack_trace": "%exception{10}"
|
||||
}
|
||||
</pattern>
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<springProfile name="local">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="dev">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="test">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="pre">
|
||||
<root level="debug">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="master">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<!-- <appender-ref ref="DEBUG"/>-->
|
||||
<appender-ref ref="JSON_STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
||||
@ -0,0 +1,23 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-test</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
128
archetype-simple/src/main/resources/archetype-resources/pom.xml
Normal file
128
archetype-simple/src/main/resources/archetype-resources/pom.xml
Normal file
@ -0,0 +1,128 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<commons-collections4.version>4.4</commons-collections4.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<hutool-all.version>5.5.7</hutool-all.version>
|
||||
<logstash-logback-encoder.version>6.1</logstash-logback-encoder.version>
|
||||
<xxl.job.version>2.2.0</xxl.job.version>
|
||||
<redisson.version>3.13.2</redisson.version>
|
||||
<fastjson.version>1.2.47</fastjson.version>
|
||||
<joda-time.version>2.10.6</joda-time.version>
|
||||
<javax.validation.version>2.0.0.Final</javax.validation.version>
|
||||
<hibernate.validator.version>6.0.16.Final</hibernate.validator.version>
|
||||
<http.client.version>4.5.6</http.client.version>
|
||||
<mybatis-plus.version>3.3.2</mybatis-plus.version>
|
||||
<velocity-engine-core.version>2.0</velocity-engine-core.version>
|
||||
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- spring cloud -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<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>
|
||||
<!-- database -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!-- tool -->
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
<version>${logstash-logback-encoder.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${javax.validation.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate.validator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${http.client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool-all.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>${velocity-engine-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
<!-- middleware -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>${xxl.job.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
33
archetype-standard/.gitignore
vendored
Normal file
33
archetype-standard/.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# maven ignore
|
||||
target/
|
||||
*.jar
|
||||
*.war
|
||||
*.zip
|
||||
*.tar
|
||||
*.tar.gz
|
||||
|
||||
# eclipse ignore
|
||||
.settings/
|
||||
.project
|
||||
.classpath
|
||||
|
||||
# idea ignore
|
||||
.idea/
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
|
||||
# temp ignore
|
||||
logs/
|
||||
*.doc
|
||||
*.log
|
||||
*.cache
|
||||
*.diff
|
||||
*.patch
|
||||
*.tmp
|
||||
|
||||
# system ignore
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.class
|
||||
34
archetype-standard/README.md
Normal file
34
archetype-standard/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# archetype-standard
|
||||
|
||||
公司项目标准骨架
|
||||
|
||||
## xxx-common
|
||||
通用模块,包前缀标准为:``cn.axzo.xxx.common.`` 里面可以定义 constants 包用来定义系统中使用到的常量值;context 包用来定义系统当中要使用到的上下文;enums 包用来定义系统当中使用到的枚举值;utils 包用来定义系统当中的工具类等。
|
||||
|
||||
因为这个模块都会被其它模块引用,所以这个模块的 pom.xml 依赖的 jar 包必须是公共能用的,比如:lombok,common-utils ,guava,fastjson 等。不应该引用的 jar 比如携程的配置中心 apollo(xxx-client 依赖);远程服务调用 dubbo 或者 feign (xxx-integration 依赖)。
|
||||
|
||||
## xxx-dal
|
||||
数据访问模块,包前缀标准为:``cn.axzo.xxx.dal.`` 里面可以定义 mapper 包用来定义服务访问 mapper 接口;repository 包用来定义包装 mapper 接口(主要功能是可以代理增强 mapper);entity 包用来定义数据库实体访问对象。domain 包用来定义访问数据库的请求对象等。
|
||||
|
||||
因为这个模块的主要功能是访问数据库,所以这个模块的 pom.xml 依赖的 jar 包应该是和数据访问相关的。比如:jdbc 驱动;mybatis 等
|
||||
|
||||
## xxx-integration
|
||||
外部接口集成模块,包前缀标准为:``cn.axzo.xxx.integration.`` 里面可以定义 service 包用来定义 feign 接口,定义 client 接口用来包装 service 包中的接口(代理增强 service:打印日志,异常处理);可以定义 dto 包用来定义远程请求与响应对象。
|
||||
|
||||
## xxx-client
|
||||
请求处理模块,包前缀标准为:``cn.axzo.xxx.client.`` 里面可以定义 controller 包用于定义响应前端请求的控制器,config 包用于定义整个项目的配置(Redis 配置,Xxl Job 配置,Spring Web 统一异常配置,数据库配置等),interceptor 包用来定义 spring mvc 中的拦截器等。
|
||||
|
||||
## xxx-service-api
|
||||
业务逻辑模块,包前缀标准为:``cn.axzo.xxx.service.api.`` 里面定义的接口直接给 xxx-client 中的 controller 调用,所有的业务逻辑都会被封装到它的实现类当中。业务 Controller 只会调用这个 Service 并不关注具体的业务实现细节。可以定义 request 包用于 service 接口的请求参数,可以定义 response 用于 service 接口的响应参数。
|
||||
|
||||
## xxx-service
|
||||
业务逻辑实现模块,是 xxx-service-api 模块定义的接口的实现类接口,包前缀标准为:``cn.axzo.xxx.service.impl.``.它是聚合 xxx-manager 这个通用处理层的,它主要是集成数据库访问以及第三方接口的调用。它的作用是业务逻辑的编排。
|
||||
|
||||
## xxx-manager-api
|
||||
通用逻辑模块,包前缀标准为:``cn.axzo.xxx.manager.api.``,可以是访问数据库的一些逻辑的编排,也可以是定义一些公共的逻辑处理,比如:时间处理 Manager,分布式锁 Manager 等
|
||||
|
||||
## xxx-manager
|
||||
能用逻辑实现模块:包前缀标准为:``cn.axzo.xxx.manager.impl.``。它对访问数据库的一些逻辑的编排达到操作的原子性,同时也实现一些公共逻辑处理的一些实现。
|
||||
|
||||
## xxx-test:
|
||||
单元测试模块:所有模块的单元测试都可以放在这个模块里。
|
||||
20
archetype-standard/pom.xml
Normal file
20
archetype-standard/pom.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>cn.axzo.archetype</groupId>
|
||||
<artifactId>archetype-standard</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>archetype-standard</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archetype-descriptor
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
|
||||
name="demo-parent"
|
||||
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modules>
|
||||
<module id="${rootArtifactId}-client" dir="__rootArtifactId__-client" name="${rootArtifactId}-client">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
<include>**/*.yml</include>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-common" dir="__rootArtifactId__-common" name="${rootArtifactId}-common">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-dal" dir="__rootArtifactId__-dal" name="${rootArtifactId}-dal">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-integration" dir="__rootArtifactId__-integration" name="${rootArtifactId}-integration">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-manager" dir="__rootArtifactId__-manager" name="${rootArtifactId}-manager">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-manager-api" dir="__rootArtifactId__-manager-api" name="${rootArtifactId}-manager-api">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-service" dir="__rootArtifactId__-service" name="${rootArtifactId}-service">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-service-api" dir="__rootArtifactId__-service-api" name="${rootArtifactId}-service-api">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/main/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
<module id="${rootArtifactId}-test" dir="__rootArtifactId__-test" name="${rootArtifactId}-test">
|
||||
<fileSets>
|
||||
<fileSet filtered="true" packaged="true" encoding="UTF-8">
|
||||
<directory>src/test/java</directory>
|
||||
<includes>
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet filtered="true" encoding="UTF-8">
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**/*.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</module>
|
||||
</modules>
|
||||
</archetype-descriptor>
|
||||
@ -0,0 +1,42 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-client</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.client;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ClientTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,201 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||
<!--属性-->
|
||||
<property name="PROJECT_NAME" value="bcap"/>
|
||||
<!--日志路径-->
|
||||
<property name="LOG_PATH" value="logs"/>
|
||||
<!-- 日志最大的历史 30天 -->
|
||||
<property name="MAX_HISTORY" value="30"/>
|
||||
<!--默认日志输出模式-->
|
||||
<property name="LOG_PATTERN"
|
||||
value="[%date{yyyy-MM-dd HH:mm:ss:SSS}] [%level] [%thread] [%X{ctxLogId}] [axzo-bcap-service] [%class{36}#%M:%L] %msg%n"/>
|
||||
<!--环境名-->
|
||||
<contextName>${PROJECT_NAME}</contextName>
|
||||
|
||||
<!--错误日志-->
|
||||
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_PATH}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/error/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>error</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/warn.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/warn/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>warn</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/info.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/info/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>info</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
<appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_PATH}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_PATH}/debug/debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<maxHistory>${MAX_HISTORY}</maxHistory>
|
||||
</rollingPolicy>
|
||||
<!-- 追加方式记录日志 -->
|
||||
<append>true</append>
|
||||
<!-- 日志文件的格式 -->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<!-- 此日志文件记录error级别的 -->
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>debug</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- ConsoleAppender 控制台输出日志 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender" addtivity="false">
|
||||
<encoder>
|
||||
<pattern>${LOG_PATTERN}</pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>info</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- ConsoleAppender 控制台输出日志 -->
|
||||
<appender name="JSON_STDOUT" class="ch.qos.logback.core.ConsoleAppender" addtivity="false">
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
|
||||
<providers>
|
||||
<timestamp>
|
||||
<fieldName>@timestamp</fieldName>
|
||||
<pattern>yyyy-MM-dd'T'HH:mm:ss.SSSx</pattern>
|
||||
<timeZone>GMT+8</timeZone>
|
||||
</timestamp>
|
||||
<pattern>
|
||||
<pattern>
|
||||
{
|
||||
<!--
|
||||
"@timestamp":"%date{ISO8601}",
|
||||
-->
|
||||
"app": "${appName}",
|
||||
"level": "%level",
|
||||
<!-- "trace": "%X{X-B3-TraceId:-}",
|
||||
"span": "%X{X-B3-SpanId:-}",
|
||||
"parent": "%X{X-B3-ParentSpanId:-}",-->
|
||||
"thread": "%thread",
|
||||
"class": "%logger{40}",
|
||||
"message":"%message",
|
||||
"m":"#asJson{%message}",
|
||||
"stack_trace": "%exception{10}"
|
||||
}
|
||||
</pattern>
|
||||
</pattern>
|
||||
</providers>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<springProfile name="local">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="dev">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="test">
|
||||
<root level="info">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="pre">
|
||||
<root level="debug">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<appender-ref ref="DEBUG"/>
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
<springProfile name="master">
|
||||
<root level="INFO">
|
||||
<appender-ref ref="ERROR"/>
|
||||
<appender-ref ref="WARN"/>
|
||||
<appender-ref ref="INFO"/>
|
||||
<!-- <appender-ref ref="DEBUG"/>-->
|
||||
<appender-ref ref="JSON_STDOUT"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
</configuration>
|
||||
@ -0,0 +1,63 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.common;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class CommonTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-dal</artifactId>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.dal;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class DalTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-integration</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.integration;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class IntegrationTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-manager-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-dal</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.manager.api;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ManagerTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-manager</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-dal</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-manager-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-integration</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.manager.impl;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ManagerTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-service-api</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-manager-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.service.api;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ServiceTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-service-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-manager</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,9 @@
|
||||
package ${package}.service.impl;
|
||||
|
||||
/**
|
||||
* @author zhaoyong
|
||||
*
|
||||
*/
|
||||
public class ServiceTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</parent>
|
||||
<artifactId>${rootArtifactId}-test</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,128 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${rootArtifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<commons-collections4.version>4.4</commons-collections4.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<hutool-all.version>5.5.7</hutool-all.version>
|
||||
<logstash-logback-encoder.version>6.1</logstash-logback-encoder.version>
|
||||
<xxl.job.version>2.2.0</xxl.job.version>
|
||||
<redisson.version>3.13.2</redisson.version>
|
||||
<fastjson.version>1.2.47</fastjson.version>
|
||||
<joda-time.version>2.10.6</joda-time.version>
|
||||
<javax.validation.version>2.0.0.Final</javax.validation.version>
|
||||
<hibernate.validator.version>6.0.16.Final</hibernate.validator.version>
|
||||
<http.client.version>4.5.6</http.client.version>
|
||||
<mybatis-plus.version>3.3.2</mybatis-plus.version>
|
||||
<velocity-engine-core.version>2.0</velocity-engine-core.version>
|
||||
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- spring cloud -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<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>
|
||||
<!-- database -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!-- tool -->
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${joda-time.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
<version>${logstash-logback-encoder.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${javax.validation.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate.validator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${http.client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool-all.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>${velocity-engine-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>${commons-collections4.version}</version>
|
||||
</dependency>
|
||||
<!-- middleware -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>${xxl.job.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
33
common-common/.gitignore
vendored
Normal file
33
common-common/.gitignore
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# maven ignore
|
||||
target/
|
||||
*.jar
|
||||
*.war
|
||||
*.zip
|
||||
*.tar
|
||||
*.tar.gz
|
||||
|
||||
# eclipse ignore
|
||||
.settings/
|
||||
.project
|
||||
.classpath
|
||||
|
||||
# idea ignore
|
||||
.idea/
|
||||
*.ipr
|
||||
*.iml
|
||||
*.iws
|
||||
|
||||
# temp ignore
|
||||
logs/
|
||||
*.doc
|
||||
*.log
|
||||
*.cache
|
||||
*.diff
|
||||
*.patch
|
||||
*.tmp
|
||||
|
||||
# system ignore
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.class
|
||||
33
common-common/pom.xml
Normal file
33
common-common/pom.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>common-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,93 @@
|
||||
package cn.azxo.framework.common.spring;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 抽象简单可自动注册服务工厂,自动发现服务
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @since 2020-07-07
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractSimpleRegisterableServiceFactory<RouteKey, Service extends SimpleRegisterableService<RouteKey>>
|
||||
implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
protected Map<RouteKey, Service> serviceMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 返回服务工厂名称
|
||||
*/
|
||||
protected abstract String getFactoryName();
|
||||
|
||||
/**
|
||||
* 返回自动发现服务的接口类型
|
||||
*/
|
||||
protected abstract Class<Service> getServiceClazz();
|
||||
|
||||
/**
|
||||
* 返回服务
|
||||
* @param routeKey 路由对象
|
||||
* @return 如果无匹配服务返回null
|
||||
*/
|
||||
public Service getService(RouteKey routeKey) {
|
||||
return serviceMap.get(routeKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
try {
|
||||
Map<String, Service> services = event.getApplicationContext().getBeansOfType(getServiceClazz());
|
||||
if (CollectionUtils.isEmpty(services)) {
|
||||
return;
|
||||
}
|
||||
beforeRegisterAll();
|
||||
for (Map.Entry<String, Service> entry : services.entrySet()) {
|
||||
registerService(entry.getKey(), entry.getValue());
|
||||
}
|
||||
afterRegisterAll();
|
||||
} finally {
|
||||
MDC.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在所有注册之前
|
||||
*/
|
||||
protected void beforeRegisterAll() {
|
||||
log.info("开始初始化简单服务工厂: {}", getFactoryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认注册服务实现,Map管理服务,key是路由对象,value是服务
|
||||
* @param beanName bean名称
|
||||
* @param service 服务实例
|
||||
*/
|
||||
protected void registerService(String beanName, Service service) {
|
||||
RouteKey routeKey = service.getRouteKey();
|
||||
if (routeKey == null) {
|
||||
throw new RuntimeException(String.format("注册服务路由对象不可为空:%s", service.getClass()));
|
||||
}
|
||||
if (!serviceMap.containsKey(routeKey)) {
|
||||
serviceMap.put(routeKey, service);
|
||||
log.info("已注册服务: {}, {}", routeKey, service.getClass());
|
||||
} else {
|
||||
throw new RuntimeException(String.format("注册服务路由对象重复: %s, %s, %s", routeKey,
|
||||
serviceMap.get(routeKey).getClass(), service.getClass()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在所有注册之后
|
||||
*/
|
||||
protected void afterRegisterAll() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.azxo.framework.common.spring;
|
||||
|
||||
/**
|
||||
* 简单可自动注册服务,根据路由对象直接路由
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @since 2020-07-07
|
||||
*/
|
||||
public interface SimpleRegisterableService<RouteKey> {
|
||||
|
||||
/**
|
||||
* 返回用于路由服务的对象
|
||||
*
|
||||
* @return RouteKey
|
||||
*/
|
||||
RouteKey getRouteKey();
|
||||
|
||||
}
|
||||
70
pom.xml
Normal file
70
pom.xml
Normal file
@ -0,0 +1,70 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>archetype-simple</module>
|
||||
<module>archetype-standard</module>
|
||||
<module>common-common</module>
|
||||
<module>smart-datasource</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<revision>1.0.0</revision>
|
||||
<!-- tool -->
|
||||
<aspectj.version>1.7.3</aspectj.version>
|
||||
<aopalliance.version>1.0</aopalliance.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- AspectJ -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>${aspectj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>aopalliance</groupId>
|
||||
<artifactId>aopalliance</artifactId>
|
||||
<version>${aopalliance.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>4.3.19.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>4.3.19.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
43
smart-datasource/pom.xml
Normal file
43
smart-datasource/pom.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>smart-datasource</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>aopalliance</groupId>
|
||||
<artifactId>aopalliance</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,23 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 分片自定义数据源
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see DataSource
|
||||
* @since 2020-03-27 13:49
|
||||
*/
|
||||
@Documented
|
||||
@Target({ElementType.METHOD,ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DataSource {
|
||||
|
||||
String value() default "";
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcut;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 数据源 Pointcut
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see DataSourcePointcut
|
||||
* @since 2020-03-27 15:57
|
||||
*/
|
||||
public class DataSourcePointcut extends StaticMethodMatcherPointcut {
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class<?> aClass) {
|
||||
return matchesInternal(method) || matchesInternal(aClass);
|
||||
}
|
||||
|
||||
private boolean matchesInternal(AnnotatedElement annotatedElement) {
|
||||
return annotatedElement.getAnnotation(DataSource.class) != null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
/**
|
||||
* 数据源上下文 Holder
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see DatasourceContextHolder
|
||||
* @since 2020-03-27 13:24
|
||||
*/
|
||||
public class DatasourceContextHolder {
|
||||
|
||||
public static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
|
||||
|
||||
public static void setDataSourceKey(String dataSourceKey) {
|
||||
contextHolder.set(dataSourceKey);
|
||||
}
|
||||
|
||||
public static String getDataSourceKey() {
|
||||
return contextHolder.get();
|
||||
}
|
||||
|
||||
public static void clearDataSourceKey() {
|
||||
contextHolder.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 激活动态数据源
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see EnableDataSource
|
||||
* @since 2020-03-27 14:18
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Import(ShardingConfigurationSelector.class)
|
||||
public @interface EnableDataSource {
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Role;
|
||||
|
||||
/**
|
||||
* 分片配置类
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see ProxyShardingConfiguration
|
||||
* @since 2020-03-27 14:52
|
||||
*/
|
||||
@Configuration
|
||||
public class ProxyShardingConfiguration {
|
||||
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@Bean
|
||||
public DefaultBeanFactoryPointcutAdvisor shardingAdvisor() {
|
||||
DefaultBeanFactoryPointcutAdvisor advisor = new DefaultBeanFactoryPointcutAdvisor();
|
||||
advisor.setPointcut(dataSourcePointcut());
|
||||
advisor.setAdvice(shardingInterceptor());
|
||||
return advisor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public DataSourcePointcut dataSourcePointcut(){
|
||||
return new DataSourcePointcut();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public ShardingInterceptor shardingInterceptor() {
|
||||
ShardingInterceptor interceptor = new ShardingInterceptor();
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* 分片配置 Selector
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see ShardingConfigurationSelector
|
||||
* @since 2020-03-27 14:22
|
||||
*/
|
||||
public class ShardingConfigurationSelector implements ImportSelector {
|
||||
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
return new String[] {ProxyShardingConfiguration.class.getName()};
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.MethodClassKey;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 数据源切换切面
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see ShardingInterceptor
|
||||
* @since 2020-03-27 15:42
|
||||
*/
|
||||
public class ShardingInterceptor implements MethodInterceptor {
|
||||
|
||||
private final static String NULL_DATASOURCE_ATTRIBUTE = "null";
|
||||
|
||||
private final Map<Object, String> attributeCache = new ConcurrentHashMap<>(1024);
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method method = invocation.getMethod();
|
||||
Class<?> declaringClass = invocation.getMethod().getDeclaringClass();
|
||||
String dataSourceAttribute = getDataSourceAttribute(method, declaringClass);
|
||||
if(StringUtils.hasText(dataSourceAttribute)){
|
||||
DatasourceContextHolder.setDataSourceKey(dataSourceAttribute);
|
||||
}
|
||||
Object result;
|
||||
try {
|
||||
result = invocation.proceed();
|
||||
} finally {
|
||||
DatasourceContextHolder.clearDataSourceKey();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getDataSourceAttribute(Method method, Class<?> targetClass) {
|
||||
if (method.getDeclaringClass() == Object.class) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// First, see if we have a cached value.
|
||||
Object cacheKey = getCacheKey(method, targetClass);
|
||||
String cached = this.attributeCache.get(cacheKey);
|
||||
if (cached != null) {
|
||||
// Value will either be canonical value indicating there is no transaction attribute,
|
||||
// or an actual transaction attribute.
|
||||
if (cached == NULL_DATASOURCE_ATTRIBUTE) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return cached;
|
||||
}
|
||||
} else {
|
||||
// We need to work it out.
|
||||
String txAttr = computeDataSourceAttribute(method, targetClass);
|
||||
// Put it in the cache.
|
||||
if (StringUtils.hasText(txAttr)) {
|
||||
this.attributeCache.put(cacheKey, txAttr);
|
||||
} else {
|
||||
this.attributeCache.put(cacheKey, NULL_DATASOURCE_ATTRIBUTE);
|
||||
}
|
||||
return txAttr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine a cache key for the given method and target class.
|
||||
* <p>Must not produce same key for overloaded methods.
|
||||
* Must produce same key for different instances of the same method.
|
||||
* @param method the method (never {@code null})
|
||||
* @param targetClass the target class (may be {@code null})
|
||||
* @return the cache key (never {@code null})
|
||||
*/
|
||||
protected Object getCacheKey(Method method, Class<?> targetClass) {
|
||||
return new MethodClassKey(method, targetClass);
|
||||
}
|
||||
|
||||
private String computeDataSourceAttribute(Method method, Class<?> targetClass){
|
||||
// Ignore CGLIB subclasses - introspect the actual user class.
|
||||
Class<?> userClass = ClassUtils.getUserClass(targetClass);
|
||||
// The method may be on an interface, but we need attributes from the target class.
|
||||
// If the target class is null, the method will be unchanged.
|
||||
Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);
|
||||
// If we are dealing with method with generic parameters, find the original method.
|
||||
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
|
||||
// First try is the method in the target class.
|
||||
String txAttr = findDataSourceAttribute(specificMethod);
|
||||
if (txAttr != null) {
|
||||
return txAttr;
|
||||
}
|
||||
// Second try is the transaction attribute on the target class.
|
||||
txAttr = findDataSourceAttribute(specificMethod.getDeclaringClass());
|
||||
if (txAttr != null && ClassUtils.isUserLevelMethod(method)) {
|
||||
return txAttr;
|
||||
}
|
||||
if (specificMethod != method) {
|
||||
// Fallback is to look at the original method.
|
||||
txAttr = findDataSourceAttribute(method);
|
||||
if (txAttr != null) {
|
||||
return txAttr;
|
||||
}
|
||||
// Last fallback is the class of the original method.
|
||||
txAttr = findDataSourceAttribute(method.getDeclaringClass());
|
||||
if (txAttr != null && ClassUtils.isUserLevelMethod(method)) {
|
||||
return txAttr;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String findDataSourceAttribute(AnnotatedElement annotatedElement){
|
||||
DataSource dataSourceAnnotation = annotatedElement.getAnnotation(DataSource.class);
|
||||
if(dataSourceAnnotation != null) {
|
||||
return dataSourceAnnotation.value();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.azxo.framework.datasource;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
/**
|
||||
* 智能分片数据源
|
||||
*
|
||||
* @author zhaoyong_sh
|
||||
* @see SmartDatasource
|
||||
* @since 2020-03-27 11:30
|
||||
*/
|
||||
public class SmartDatasource extends AbstractRoutingDataSource implements PriorityOrdered {
|
||||
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DatasourceContextHolder.getDataSourceKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user