diff --git a/README.md b/README.md index d61b948..77f46d3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ - [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) 分布式锁 + + + > 每个模块可单独引用使用,不耦合 @@ -76,4 +81,43 @@ public String test(@GetTimestamp LocalDateTime time) { return time.toString(); } +``` + +# 依赖 + +- web +```xml + + + io.github.weihubeats + spring-boot-nebula-web + 0.0.01 + +``` + +- 分布式锁 +```xml + + io.github.weihubeats + spring-boot-nebula-distribute-lock + 0.0.01 + +``` + +- ddd聚合根组件 +```xml + + io.github.weihubeats + spring-boot-nebula-aggregate + 0.0.01 + +``` + +- mybatis-plus +```xml + + io.github.weihubeats + spring-boot-nebula-mybatis-plus + 0.0.01 + ``` \ No newline at end of file diff --git a/spring-boot-nebula-aop-base/pom.xml b/spring-boot-nebula-aop-base/pom.xml index e5bf733..32e5e5f 100644 --- a/spring-boot-nebula-aop-base/pom.xml +++ b/spring-boot-nebula-aop-base/pom.xml @@ -18,11 +18,17 @@ + org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-aop + + org.projectlombok lombok diff --git a/spring-boot-nebula-dependencies/pom.xml b/spring-boot-nebula-dependencies/pom.xml index 79f22b7..dd06b22 100644 --- a/spring-boot-nebula-dependencies/pom.xml +++ b/spring-boot-nebula-dependencies/pom.xml @@ -72,6 +72,12 @@ ${revision} + + io.github.weihubeats + spring-boot-nebula-distribute-lock + ${revision} + + com.google.guava guava @@ -107,5 +113,151 @@ + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + weihubeats + weihu@apche.org + https://weihubeats.blog.csdn.net/ + + + + + scm:git@github.com:weihubeats/spring-boot-common.git + scm:git@github.com:weihubeats/spring-boot-common.git + git@github.com:weihubeats/spring-boot-common.git + + + + Github Issue + https://github.com/weihubeats/spring-boot-common/issues + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + true + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + true + + 1 + false + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + true + + + + package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + ${java.home}/bin/javadoc + + -Xdoclint:none + + + + + package + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + org.codehaus.mojo + flatten-maven-plugin + ${flatten-maven-plugin.version} + + true + resolveCiFriendliesOnly + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + + + + sonatype + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + sonatype + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + \ No newline at end of file diff --git a/spring-boot-nebula-mybatis/pom.xml b/spring-boot-nebula-mybatis/pom.xml index d2c2f24..96cd798 100644 --- a/spring-boot-nebula-mybatis/pom.xml +++ b/spring-boot-nebula-mybatis/pom.xml @@ -6,7 +6,7 @@ io.github.weihubeats spring-boot-nebula - 0.0.01 + ${revision} spring-boot-nebula-mybatis diff --git a/spring-boot-nebula-samples/pom.xml b/spring-boot-nebula-samples/pom.xml index 697605c..6dd988e 100644 --- a/spring-boot-nebula-samples/pom.xml +++ b/spring-boot-nebula-samples/pom.xml @@ -9,6 +9,7 @@ spring-boot-nebula-web-sample + spring-boot-nebula-distribute-lock-sample 4.0.0 @@ -19,6 +20,7 @@ 8 8 + true \ No newline at end of file diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/pom.xml b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/pom.xml new file mode 100644 index 0000000..482a4c2 --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + io.github.weihubeats + spring-boot-nebula-samples + ${revision} + + + spring-boot-nebula-distribute-lock-sample + + + 11 + 11 + UTF-8 + + + + + io.github.weihubeats + spring-boot-nebula-web + + + + io.github.weihubeats + spring-boot-nebula-distribute-lock + + + + + \ No newline at end of file diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/http/http-test-controller.http b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/http/http-test-controller.http new file mode 100644 index 0000000..0d3929d --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/http/http-test-controller.http @@ -0,0 +1 @@ +GET localhost:8088/test \ No newline at end of file diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/DistributeLockApplication.java b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/DistributeLockApplication.java new file mode 100644 index 0000000..b457bfb --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/DistributeLockApplication.java @@ -0,0 +1,18 @@ +package com.nebula.distribute.lock.sample; + +import java.util.TimeZone; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Hello world! + * + */ +@SpringBootApplication +public class DistributeLockApplication { + + public static void main(String[] args) { + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); + SpringApplication.run(DistributeLockApplication.class, args); + } +} diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/config/RedissonConfig.java b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/config/RedissonConfig.java new file mode 100644 index 0000000..d2ced1a --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/config/RedissonConfig.java @@ -0,0 +1,45 @@ +package com.nebula.distribute.lock.sample.config; + +import com.nebula.base.utils.DataUtils; +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.codec.JsonJacksonCodec; +import org.redisson.config.Config; +import org.redisson.config.SingleServerConfig; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author : wh + * @date : 2024/3/16 11:02 + * @description: + */ +@Configuration +public class RedissonConfig { + + @Value("${redis.host}") + private String redisLoginHost; + @Value("${redis.port}") + private Integer redisLoginPort; + @Value("${redis.password}") + private String redisLoginPassword; + + + @Bean + public RedissonClient redissonClient() { + return createRedis(redisLoginHost, redisLoginPort, redisLoginPassword); + } + + private RedissonClient createRedis(String redisHost, Integer redisPort, String redisPassword) { + Config config = new Config(); + SingleServerConfig singleServerConfig = config.useSingleServer(); + singleServerConfig.setAddress("redis://" + redisHost + ":" + redisPort + ""); + singleServerConfig.setDatabase(1); + if (DataUtils.isNotEmpty(redisPassword)) { + singleServerConfig.setPassword(redisPassword); + } + config.setCodec(new JsonJacksonCodec()); + return Redisson.create(config); + } +} diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/controller/TestController.java b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/controller/TestController.java new file mode 100644 index 0000000..4c6125d --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/controller/TestController.java @@ -0,0 +1,30 @@ +package com.nebula.distribute.lock.sample.controller; + +import com.nebula.distribute.lock.sample.service.TestService; +import com.nebula.web.boot.annotation.NebulaResponseBody; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author : wh + * @date : 2023/8/2 10:28 + * @description: + */ +@RestController +@RequestMapping() +@RequiredArgsConstructor +public class TestController { + + private final TestService testServcie; + + + @GetMapping("/test") + @NebulaResponseBody + public String test() throws Exception{ + testServcie.test(); + return "小奏"; + } + +} diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/service/TestService.java b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/service/TestService.java new file mode 100644 index 0000000..77663b8 --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/java/com/nebula/distribute/lock/sample/service/TestService.java @@ -0,0 +1,26 @@ +package com.nebula.distribute.lock.sample.service; + +import com.nebula.distribute.lock.annotation.NebulaDistributedLock; +import java.util.concurrent.TimeUnit; +import org.springframework.stereotype.Service; + +/** + * @author : wh + * @date : 2024/3/16 13:55 + * @description: + */ +@Service +public class TestService { + + @NebulaDistributedLock(lockName = "wh-test") + public void test() { + System.out.println("处理器请求中"); + try { + TimeUnit.SECONDS.sleep(5); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.out.println("请求处理完成"); + } + +} diff --git a/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/resources/application.yaml b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/resources/application.yaml new file mode 100644 index 0000000..01c530e --- /dev/null +++ b/spring-boot-nebula-samples/spring-boot-nebula-distribute-lock-sample/src/main/resources/application.yaml @@ -0,0 +1,13 @@ +spring: + profiles: + active: test + application: + name: web-test + +server: + port: 8088 + +redis: + host: 127.0.0.1 + port: 6379 + password: 123456 diff --git a/spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/Application.java b/spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/WebApplication.java similarity index 79% rename from spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/Application.java rename to spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/WebApplication.java index d4fe7c5..c8cf30b 100644 --- a/spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/Application.java +++ b/spring-boot-nebula-samples/spring-boot-nebula-web-sample/src/main/java/com/nebula/web/sample/WebApplication.java @@ -9,10 +9,10 @@ * */ @SpringBootApplication -public class Application { +public class WebApplication { public static void main(String[] args) { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); - SpringApplication.run(Application.class, args); + SpringApplication.run(WebApplication.class, args); } } diff --git a/spring-boot-nebula-web/src/test/java/ActionTest.java b/spring-boot-nebula-web/src/test/java/ActionTest.java index a09f120..c7c2fac 100644 --- a/spring-boot-nebula-web/src/test/java/ActionTest.java +++ b/spring-boot-nebula-web/src/test/java/ActionTest.java @@ -13,7 +13,5 @@ public class ActionTest { @Test public void test() { System.out.println("hahah"); - throw new RuntimeException("测试异常"); - } } diff --git a/spring-boot-nebula-web/src/test/java/com/nebula/web/boot/api/NebulaPageTest.java b/spring-boot-nebula-web/src/test/java/com/nebula/web/boot/api/NebulaPageTest.java index 583a7ea..3a6c163 100644 --- a/spring-boot-nebula-web/src/test/java/com/nebula/web/boot/api/NebulaPageTest.java +++ b/spring-boot-nebula-web/src/test/java/com/nebula/web/boot/api/NebulaPageTest.java @@ -12,8 +12,6 @@ public class NebulaPageTest { @Test public void testGetTotalCount() { System.out.println("hahah"); - throw new RuntimeException("测试异常"); - } } \ No newline at end of file