Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update workflow #2

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
junit:
strategy:
matrix:
java: [ 8, 11, 17 ]
java: [11]
os: [ 'windows-latest', 'ubuntu-latest' ]

runs-on: ${{ matrix.os }}
Expand All @@ -33,4 +33,4 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Test with Maven
run: mvn clean test -B -U -Psonatype
run: mvn clean test -B -U
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# spring-boot-nebula

# 模块说明
- [spring-boot-nebula-common](spring-boot-nebula-common) 基础工具组件
- [spring-boot-nebula-aggregate](spring-boot-nebula-aggregate) ddd聚合根组件
- [spring-boot-nebula-dependencies](spring-boot-nebula-dependencies) 统一依赖
- [spring-boot-nebula-samples](spring-boot-nebula-samples) 使用示例
- [spring-boot-nebula-web](spring-boot-nebula-web) web封装组件(包括统一异常返回,简化返回,自定义异常报警)
- [spring-boot-nebula-web-common](spring-boot-nebula-web-common) web模块基础工具类
- [spring-boot-nebula-distribute-lock](spring-boot-nebula-distribute-lock) 分布式锁




> 每个模块可单独引用使用,不耦合

## 解决问题
1. 统一公司所有`spring boot`项目的依赖管理

不使用`common`可能存在的问题:
- a项目使用了 redission 3.14 b项目 使用3.61,然后导致相同代码可能运行结果不一致
- 统一使用`web-spring-boot-start`模块或者`boot-common-parent`可解决不同项目依赖版本不一致问题。
在`boot-common-parent`管理公司的所有依赖,以后应用项目无需手动指定各种依赖版本只需引用依赖即可,统一在`boot-common-parent`管理即可
4. 提供开箱即用的`web-spring-boot-start`模块
4. 提供开箱即用的`web-spring-boot-start`模块,解决web开发需要手动封装工具类的痛点


## demo
Expand Down Expand Up @@ -57,3 +71,53 @@
- [NebulaPageQuery.java](spring-boot-nebula-web%2Fsrc%2Fmain%2Fjava%2Fcom%2Fnebula%2Fweb%2Fboot%2Fapi%2FNebulaPageQuery.java)

使用

#### 提供时间戳自动转`LocalDateTime`注解
@GetTimestamp

```java
@GetMapping("/test")
@NebulaResponseBody
public String test(@GetTimestamp LocalDateTime time) {
return time.toString();
}
```

# 依赖

- web
```xml

<dependency>
<groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula-web</artifactId>
<version>0.0.01</version>
</dependency>
```

- 分布式锁
```xml
<dependency>
<groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula-distribute-lock</artifactId>
<version>0.0.01</version>
</dependency>
```

- ddd聚合根组件
```xml
<dependency>
<groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula-aggregate</artifactId>
<version>0.0.01</version>
</dependency>
```

- mybatis-plus
```xml
<dependency>
<groupId>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula-mybatis-plus</artifactId>
<version>0.0.01</version>
</dependency>
```
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<module>spring-boot-nebula-common</module>
<module>spring-boot-nebula-samples</module>
<module>spring-boot-nebula-aggregate</module>
<module>spring-boot-nebula-mybatis</module>
<module>spring-boot-nebula-aop-base</module>
<module>spring-boot-nebula-distribute-lock</module>
<module>spring-boot-nebula-web-common</module>
</modules>

<name>spring-boot-nebula</name>
Expand Down Expand Up @@ -80,6 +84,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<inherited>true</inherited>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
Expand All @@ -89,8 +94,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<inherited>true</inherited>
<configuration>
<skipTests>true</skipTests>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<!-- <skipTests>false</skipTests>-->
</configuration>
</plugin>
<plugin>
Expand Down
7 changes: 1 addition & 6 deletions spring-boot-nebula-aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
</parent>

<artifactId>spring-boot-nebula-aggregate</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>

Expand Down
38 changes: 38 additions & 0 deletions spring-boot-nebula-aop-base/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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>io.github.weihubeats</groupId>
<artifactId>spring-boot-nebula</artifactId>
<version>${revision}</version>
</parent>

<artifactId>spring-boot-nebula-aop-base</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.nebula.aop.base;

import lombok.NonNull;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.StaticMethodMatcher;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.Assert;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
* @author : wh
* @date : 2024/3/12 17:02
* @description:
*/
public class NebulaBaseAnnotationAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware {

private final Advice advice;

private final Pointcut pointcut;

private final Class<? extends Annotation> annotation;

public NebulaBaseAnnotationAdvisor(@NonNull MethodInterceptor advice,
@NonNull Class<? extends Annotation> annotation) {
this.advice = advice;
this.annotation = annotation;
this.pointcut = buildPointcut();
}

@Override
public Pointcut getPointcut() {
return this.pointcut;
}

@Override
public Advice getAdvice() {
return this.advice;
}

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
if (this.advice instanceof BeanFactoryAware) {
((BeanFactoryAware) this.advice).setBeanFactory(beanFactory);
}
}

private Pointcut buildPointcut() {
Pointcut cpc = new AnnotationMatchingPointcut(annotation, true);
Pointcut mpc = new AnnotationMethodPoint(annotation);
return new ComposablePointcut(cpc).union(mpc);
}

/**
* In order to be compatible with the spring lower than 5.0
*/
private static class AnnotationMethodPoint implements Pointcut {

private final Class<? extends Annotation> annotationType;

public AnnotationMethodPoint(Class<? extends Annotation> annotationType) {
Assert.notNull(annotationType, "Annotation type must not be null");
this.annotationType = annotationType;
}

@Override
public ClassFilter getClassFilter() {
return ClassFilter.TRUE;
}

@Override
public MethodMatcher getMethodMatcher() {
return new AnnotationMethodMatcher(annotationType);
}

private static class AnnotationMethodMatcher extends StaticMethodMatcher {
private final Class<? extends Annotation> annotationType;

public AnnotationMethodMatcher(Class<? extends Annotation> annotationType) {
this.annotationType = annotationType;
}

@Override
public boolean matches(Method method, Class<?> targetClass) {
if (matchesMethod(method)) {
return true;
}
// Proxy classes never have annotations on their redeclared methods.
if (Proxy.isProxyClass(targetClass)) {
return false;
}
// The method may be on an interface, so let's check on the target class as well.
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
return (specificMethod != method && matchesMethod(specificMethod));
}

private boolean matchesMethod(Method method) {
return AnnotatedElementUtils.hasAnnotation(method, this.annotationType);
}
}
}
}
4 changes: 0 additions & 4 deletions spring-boot-nebula-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

<artifactId>spring-boot-nebula-common</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>

Expand Down
Loading
Loading