diff --git a/shoulder-platform-common/pom.xml b/shoulder-platform-common/pom.xml index 587e383..23be9ea 100644 --- a/shoulder-platform-common/pom.xml +++ b/shoulder-platform-common/pom.xml @@ -26,6 +26,7 @@ shoulder-platform-starter-trace shoulder-sms-aliyun-spring-boot-starter + shoulder-platform-archetype diff --git a/shoulder-platform-common/shoulder-platform-archetype/README.md b/shoulder-platform-common/shoulder-platform-archetype/README.md new file mode 100644 index 0000000..21a16d5 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/README.md @@ -0,0 +1,66 @@ +# shoulder-platform-archetype + +基于 `shoulder-platform` 的多模块的 `maven` 骨架工程,适合基于 spring cloud 的微服务模式的微服务工程。 + +## 诞生背景 + +项目中大都是分模块开发,一个模块一个工程,通过一个外层工程管理所有模块,充分利用maven的`聚合`、`继承`的特性来减少项目管理的成本。 + +> 聚合是为了管理多模块build,继承是方便依赖管理 + +目标是选择 `shoulder-platform-archetype` 便自动创建一个父模块,以及多个子模块,父模块既是聚合也可提供依赖继承。 + + +## 保姆级使用介绍 + +下面以 IDEA 为例,介绍如何通过 `shoulder-platform-archetype` 快速创建一个引入了`shoulder`的 spring boot web 工程 + +### 添加 shoulder 的 archetype + +第一次使用时需要添加,以后都不用这一步咯,`version` 不同,创建的也可能不同哦 + +``` +groupId cn.itlym.platform +artifactId shoulder-platform-archetype +version 1.0-SNAPSHOT +``` + +![添加 shoulder 的 archetype](../doc/img/archetype/idea/add.png) + + +### 基于 shoulder 提供的模板创建 maven 工程 + +#### 选择shoulder +![选择shoulder](../doc/img/archetype/idea/1.png) + +#### 输入 gourpId、artifactId +![输入 gourpId、artifactId](../doc/img/archetype/idea/2.png) + +#### 输入覆盖模板的值 +![输入覆盖模板的值](../doc/img/archetype/idea/3.png) +确保 `rootArtifactId` 和 `appId` 相同 + +#### 完成创建 +![完成创建](../doc/img/archetype/idea/4.png) + +#### 等待创建完毕 +![等待创建完毕](../doc/img/archetype/idea/5.png) +- 如果不设置缓存,这一步因访问maven官网,可能会比较慢,解决方式参考 [IDEA 创建maven工程 create from archetype 很慢](https://blog.csdn.net/qq_35425070/article/details/108958087) +- 创建完毕后,我们需要 reimport maven 依赖,这里我们直接点击自动更新 + +#### 启动运行 +![启动运行](../doc/img/archetype/idea/6.png) + +可以访问 DemoController [http://localhost:8080/demo/test](http://localhost:8080/demo/test) 查看一下 + + +--- + +## 模板属性表 +|属性 key | 说明 | 默认值 | +|----|----|----| +| appId | 应用/服务标识 | 使用 `${rootArtifactId}` 值 | +| package | 包路径 | `${groupId}.${appId}` | +| contextPath | 上下文路径 | `${appId}` | +| StartClassName | 启动类名 | ShoulderApplication | +| author | 作者名 | `${user.name}` | \ No newline at end of file diff --git a/shoulder-platform-common/shoulder-platform-archetype/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/pom.xml new file mode 100644 index 0000000..e6ab8ab --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + cn.itlym.platform + shoulder-platform-archetype + 1.0-SNAPSHOT + maven-archetype + + shoulder-platform-archetype + shoulder platform 的多模块工程模板 + + https://github.com/ChinaLym/Shoulder-Platform + + + UTF-8 + + + + + + org.apache.maven.archetype + archetype-packaging + 3.2.0 + + + + + + + maven-archetype-plugin + 3.2.0 + + + + + + + + + lym + cn_lym@foxmail.com + + + + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + + + + scm:git@github.com:ChinaLym/shoulder-framework.git + scm:git@github.com:ChinaLym/shoulder-framework.git + git@github.com:ChinaLym/shoulder-framework.git + + + + + oss + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + oss + https://oss.sonatype.org/content/repositories/snapshots + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..c171554 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,153 @@ + + + + + + + + + ${rootArtifactId} + + + + + ${groupId}.${appId} + + + + + ${appId} + + + + + ShoulderApplication + + + + + ${user.name} + + + + + + + + + + *.md + + + + + + + + + + src/main/java + + + + src/main/resources + + **/* + + + + + src/test/java + + + + + + + + src/main/java + + + + src/main/resources + + **/* + + + + + src/test/java + + + + + + + + src/main/java + + + + src/main/resources + + **/* + + + + + src/test/java + + + + + + + + + + + src/main/java + + + + src/main/resources + + **/* + + + + + src/test/java + + + + + + + + + + + src/main/java + + + + src/main/resources + + **/* + + + + + src/test/java + + + + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/README.md b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/README.md new file mode 100644 index 0000000..cca8099 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/README.md @@ -0,0 +1,2 @@ +# ${rootArtifactId} + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-api/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-api/pom.xml new file mode 100644 index 0000000..67a0c8f --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-api/pom.xml @@ -0,0 +1,33 @@ + + + + ${groupId} + ${rootArtifactId} + ${version} + + 4.0.0 + + ${artifactId} + + + + org.projectlombok + lombok + provided + + + javax.ws.rs + javax.ws.rs-api + + + javax.validation + validation-api + + + + cn.itlym + shoulder-core + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/pom.xml new file mode 100644 index 0000000..8f23252 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/pom.xml @@ -0,0 +1,20 @@ + + + + ${rootArtifactId} + ${groupId} + ${version} + + 4.0.0 + + ${artifactId} + + + + ${groupId} + ${rootArtifactId}-api + + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/src/main/java/common/controller/package-info.java b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/src/main/java/common/controller/package-info.java new file mode 100644 index 0000000..7c4192b --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-common/src/main/java/common/controller/package-info.java @@ -0,0 +1,4 @@ +/** + * 这里实现 api / ui 接口 + */ +package ${package}.common.controller; diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-core/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-core/pom.xml new file mode 100644 index 0000000..9d673cb --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-core/pom.xml @@ -0,0 +1,25 @@ + + + + ${groupId} + ${rootArtifactId} + ${version} + + 4.0.0 + + ${artifactId} + + + + ${groupId} + ${rootArtifactId}-common + + + + cn.itlym.platform + shoulder-platform-starter-micro + + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/__rootArtifactId__-xxx/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/__rootArtifactId__-xxx/pom.xml new file mode 100644 index 0000000..e350c88 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/__rootArtifactId__-xxx/pom.xml @@ -0,0 +1,13 @@ + + + + ${groupId} + ${rootArtifactId}-modules + ${version} + + 4.0.0 + + ${rootArtifactId}-xxx + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/pom.xml new file mode 100644 index 0000000..05e6a1f --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-modules/pom.xml @@ -0,0 +1,21 @@ + + + + ${groupId} + ${rootArtifactId} + ${version} + + 4.0.0 + + ${artifactId} + pom + + + + + ${groupId} + ${rootArtifactId}-core + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/pom.xml new file mode 100644 index 0000000..78715c0 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/pom.xml @@ -0,0 +1,74 @@ + + + + ${groupId} + ${rootArtifactId} + ${version} + + 4.0.0 + + ${artifactId} + ${artifactId} + ${artifactId} + + + + + ${groupId} + ${rootArtifactId}-xxx + + + + + + + + dev + + dev + + + true + + + + + + test + + test + + + + + + prod + + prod + + + + + + + ${project.artifactId} + + + + ../../dynamicConfig/config-${profile.active}.properties + + + + + src/main/resources + + **/* + + + true + + + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/java/start/controller/DemoController.java b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/java/start/controller/DemoController.java new file mode 100644 index 0000000..3c1df68 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/java/start/controller/DemoController.java @@ -0,0 +1,40 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +package ${package}.common.controller; + +import lombok.extern.shoulder.SLog; +import org.shoulder.core.log.Logger; +import org.shoulder.core.log.LoggerFactory; +import org.shoulder.web.annotation.SkipResponseWrap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * + * + * @author ${author} + */ +//@SLog // 与 @Slf4j 类似,在希望打日志的类上添加 @SLog 注解,编译时将生成类似下面定义 logger 的代码 +@SkipResponseWrap // 该类所有方法的返回值将不被包装 +@RestController +@RequestMapping("demo") +public class DemoController { + + /** + * 定义 shoulder 的 logger, 使用注解 {@link SLog} 时则可不写这行代码 + */ + private static final Logger log = LoggerFactory.getLogger(DemoController.class); + + + /** + * 访问 http://localhost:8080/demo/test 测试 + */ + @GetMapping("test") + public String test() { + return "this is a demo controller"; + } + + +} diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/banner.txt b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/banner.txt new file mode 100644 index 0000000..bdde36d --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/banner.txt @@ -0,0 +1,11 @@ +${AnsiColor.CYAN} ____ _ _ _ ${AnsiColor.BRIGHT_YELLOW} ____ _ ____ _ ${AnsiColor.CYAN} __ __ __ +${AnsiColor.CYAN}/ ___|| |__ ___ _ _| | __| | ___ _ __ ${AnsiColor.BRIGHT_YELLOW} / ___| _ _ ___| |_ ___ _ __ ___ / ___|___ _ __ | |_ ___ _ __ ${AnsiColor.CYAN} \ \ \ \ \ \ +${AnsiColor.CYAN}\___ \| '_ \ / _ \| | | | |/ _` |/ _ \ '__|${AnsiColor.BRIGHT_YELLOW} \___ \| | | / __| __/ _ \ '_ ` _ \ _____| | / _ \ '_ \| __/ _ \ '__|${AnsiColor.CYAN} \ \ \ \ \ \ +${AnsiColor.CYAN} ___) | | | | (_) | |_| | | (_| | __/ | ${AnsiColor.BRIGHT_YELLOW} ___) | |_| \__ \ || __/ | | | | |_____| |__| __/ | | | || __/ | ${AnsiColor.CYAN} / / / / / / +${AnsiColor.CYAN}|____/|_| |_|\___/ \__,_|_|\__,_|\___|_| ${AnsiColor.BRIGHT_YELLOW} |____/ \__, |___/\__\___|_| |_| |_| \____\___|_| |_|\__\___|_| ${AnsiColor.CYAN} / / / / / / +${AnsiColor.CYAN}===================================================${AnsiColor.BRIGHT_YELLOW}|___/${AnsiColor.CYAN}==========================================================/_/==/_/===/_/ + +${AnsiColor.BLUE} :: Spring Boot :: ${AnsiColor.CYAN}${spring-boot.formatted-version} +${AnsiColor.BLUE} :: Shoulder-Framework :: ${AnsiColor.CYAN}(v@shoulder.version@) +${AnsiColor.BRIGHT_GREEN} :: @project.artifactId@ :: ${AnsiColor.GREEN}(v@project.version@)${AnsiColor.CYAN} @project.description@ +${AnsiColor.DEFAULT} diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/bootstrap.yml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..62ab4de --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/bootstrap.yml @@ -0,0 +1,58 @@ +# 先从环境变量里取,若不存在,则以 maven 打包时的配置为准 +shoulder: + nacos: + ip: ${NACOS_IP:@nacos.ip@} + port: ${NACOS_PORT:@nacos.port@} + namespace: ${NACOS_ID:@nacos.namespace@} + +# spring-boot-actuate 展示信息 +info: + name: "@project.name@" + description: "@project.description@" + version: "@project.version@" + spring-boot-version: ${spring-boot.version} + spring-cloud-version: ${spring-cloud.version} + shoulder-version: "@shoulder.version@" + profile: "@profile.active@" + +# ================================== 配置正文 ================================ +spring: + #allow-bean-definition-overriding: true + application: + name: ${info.name} + profiles: + active: ${info.profile} + cloud: + nacos: + config: + server-addr: ${shoulder.nacos.ip}:${shoulder.nacos.port} # 改为自己的 nacos 地址命名空间 + file-extension: yml + # namespace: ${shoulder.nacos.namespace} # 改为自己的 nacos 地址命名空间 + shared-configs: + - dataId: common.yml + refresh: true + - dataId: ${spring.application.name}.yml + refresh: true + - dataId: redis.yml + refresh: false + - dataId: db.yml + refresh: true + - dataId: mq-rabbitmq.yml + refresh: false + enabled: true + + discovery: + server-addr: ${shoulder.nacos.ip}:${shoulder.nacos.port} + namespace: ${shoulder.nacos.namespace} + metadata: + management.context-path: ${server.servlet.context-path:}${spring.mvc.servlet.path:}${management.endpoints.web.base-path:} + +boot: + admin: + client: + url: localhost:12365 + #username: + #password: + instance: + prefer-ip: true + service-url: localhost:8080 \ No newline at end of file diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/en_US/messages.properties b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/en_US/messages.properties new file mode 100644 index 0000000..aab4037 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/en_US/messages.properties @@ -0,0 +1,2 @@ +shoulder.test.hi=hi +shoulder.test.hello=hello, {0} diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/messages.properties b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/messages.properties new file mode 100644 index 0000000..d9b64f6 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/messages.properties @@ -0,0 +1,3 @@ +shoulder.test.hi=\u55E8 +shoulder.test.hello=\u4F60\u597D,{0} +shoulder.test.cnSpecial=\u53EA\u6709\u4E2D\u6587\u7684\u8D44\u6E90\u5305\u4E2D\u6709\u8FD9\u53E5\u8BDD diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/module2.properties b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/module2.properties new file mode 100644 index 0000000..ab2ad5b --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/module2.properties @@ -0,0 +1,3 @@ +# \u7531\u4E8E\u5DE5\u7A0B\u4E2D\u53EF\u80FD\u6709\u591A\u4E2A\u6A21\u5757\uFF0Cshoulder \u5141\u8BB8\u591A\u8BED\u8A00\u6587\u4EF6\u5206\u6A21\u5757\u7EF4\u62A4 +module2.test=\u6A21\u57572\u591A\u8BED\u8A00 +module2.cnSpecial=\u6A21\u57572\u72EC\u6709 diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/readme b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/readme new file mode 100644 index 0000000..6771ac7 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/language/zh_CN/readme @@ -0,0 +1,5 @@ +# 由于工程中可能有多个模块,shoulder 允许多语言文件分模块维护 +且多语言文件命名不限,也不像原生spring那样需要为每个翻译文件配置具体的文件名,shoulder 会自动解析 + +# shoulder 会自动识别多语言翻译文件,不会加载与多语言不相干的文件(如本文件) +你可以在多语言资源文件下添加自己的说明文件,就像本文件这样,shoulder 会自动忽略 diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/static/favicon.ico b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/static/favicon.ico new file mode 100644 index 0000000..92fa7c6 Binary files /dev/null and b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/__rootArtifactId__-start/src/main/resources/static/favicon.ico differ diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/pom.xml b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..326efb7 --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,47 @@ + + + + cn.itlym.platform + shoulder-platform-parent + 1.0-SNAPSHOT + + + 4.0.0 + + ${artifactId} + + ${groupId} + pom + ${version} + + + + + ${groupId} + ${rootArtifactId}-api + ${version} + + + + ${groupId} + ${rootArtifactId}-common + ${version} + + + + ${groupId} + ${rootArtifactId}-core + ${version} + + + + + ${groupId} + ${rootArtifactId}-xxx + ${version} + + + + + + diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/test/resources/projects/basic/archetype.properties b/shoulder-platform-common/shoulder-platform-archetype/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000..5443b7a --- /dev/null +++ b/shoulder-platform-common/shoulder-platform-archetype/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,11 @@ +#Thu Oct 08 16:43:25 CST 2020 +package=cn.itlym.test +groupId=archetype.it +artifactId=basic +version=0.1-SNAPSHOT +appId=basic +StartClassName=ShoulderApplication +contextPath=basic +author=lym + +gitignore=.gitignore \ No newline at end of file diff --git a/shoulder-platform-common/shoulder-platform-archetype/src/test/resources/projects/basic/goal.txt b/shoulder-platform-common/shoulder-platform-archetype/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000..e69de29