feat(common): 脚手架部分整理

This commit is contained in:
15858193327
2020-11-01 18:02:33 +08:00
parent 9d22c83583
commit a605226609
16 changed files with 176 additions and 61 deletions

View File

@@ -2,13 +2,27 @@
Shoulder 平台各个工程的`基础设施层`统一实现(为了简化使用者调试、该工程的模块需要发布至`maven`仓库)
一般的工程模块图如下
## 工程模块图如下
![工程结构.png](../img/archetype/projectAndModule.png)
* 本模块提供了基础中间件的选型与集成,目的:统一技术栈选型。
* 本项目中一般不应引入本模块以外的能力,以保证平台的安全与易维护。
* 平台中不同系统必然存在重复的工作(中间件对接、依赖管理与维护、系统级规范与约定)在这里统一实现
* 平台项目中不应引入本模块(`shoulder-platform-common`)以外的`jar`,以保证整个平台的安全,且即使只有一个人也容易维护。
* 本工程内各个模块相当于 `shoulder-framework` 的常用 `starter`,类似 `spring-cloud-starter-xxx`
* 为了便于单人也能快速维护、未专门创新新仓库维护这些,且未发布至`maven`中央仓库。
(仓库较多,未创新新仓库维护)
----
由于各个工程必然存在重复的工作(技术选型与对接、依赖管理与维护、系统级规范与约定)在这里统一实现
## 统一更换 shoulder-framework 版本
```xml
<shoulder.version>0.4</shoulder.version><!-- shoulder-version -->
<version>0.4</version><!-- shoulder-version -->
```
## 统一更换 shoulder-platform-common 版本
```xml
<version>1.0-SNAPSHOT</version><!-- shoulder-platform-version -->
<shoulder-platform.version>1.0-SNAPSHOT</shoulder-platform.version><!-- shoulder-platform-version -->
```

View File

@@ -30,7 +30,7 @@
</modules>
<properties>
<shoulder.version>0.4-SNAPSHOT</shoulder.version><!-- shoulder-version -->
<shoulder.version>0.4</shoulder.version><!-- shoulder-version -->
<shoulder-platform.version>0.1-SNAPSHOT</shoulder-platform.version>
</properties>

View File

@@ -2,4 +2,39 @@
工程目录结构:
![目录结构](img/projectAndModule.png)
![目录结构](img/projectAndModule.png)
---
# 常见报错
## 启动后报 dataId invalid
报错内容如下:
```bash
com.alibaba.nacos.api.exception.NacosException: dataId invalid
at com.alibaba.nacos.client.config.utils.ParamUtils.checkKeyParam(ParamUtils.java:90)
at com.alibaba.nacos.client.config.NacosConfigService.getConfigInner(NacosConfigService.java:130)
at com.alibaba.nacos.client.config.NacosConfigService.getConfig(NacosConfigService.java:97)
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.loadNacosData(NacosPropertySourceBuilder.java:85)
at com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder.build(NacosPropertySourceBuilder.java:74)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:204)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosDataIfPresent(NacosPropertySourceLocator.java:191)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadApplicationConfiguration(NacosPropertySourceLocator.java:150)
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.locate(NacosPropertySourceLocator.java:103)
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:52)
at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:47)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:98)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:626)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
```
`ParamUtils.checkKeyParam(ParamUtils.java:90)` 打断点 debug 可看是加载了 nacos 哪个配置。
默认是 appId-profile默认 profile 是 `dev`)。
查看nacos中是否有对应的配置文件如果没有则在配置中心添加或 bootstrap.yml 删除声明需要加载的配置项即可。

View File

@@ -11,4 +11,13 @@
<description>持久化存储相关接口Mapper/Repository、数据库模型定义Entity/PO</description>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,40 +0,0 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.xxx.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";
}
}

View File

@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>${artifactId}</artifactId>
<name>${artifactId}</name>
<name>${appId}</name>
<description>${artifactId}</description>
<!--调试/运行/测试/打包 模块-->
@@ -63,10 +63,10 @@
<!-- maven 默认使用 artifactId+version拼接 -->
<finalName>${project.artifactId}</finalName>
<!-- 动态打包环境配置源文件 -->
<filters>
<!-- 动态打包环境配置源文件 fix shoulder-platform 中的统一配置,可删除 -->
<!--<filters>
<filter>../../dynamicConfig/config-${profile.active}.properties</filter>
</filters>
</filters>-->
<resources>
<resource>

View File

@@ -15,7 +15,75 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class ${StartClassName} {
public static void main(String[] args) {
// printColorfulShoulderBanner();
SpringApplication.run(${StartClassName}.class, args);
}
/**
* shoulder 前缀的彩色启动 banner
*/
private static void printColorfulShoulderBanner(){
// todo origin 复制自 http://patorjk.com/software/taag/#p=display&f=Ivrit&t=${rootArtifactId}
String origin =
"";
String prefix1 = "${AnsiColor.CYAN} ____ _ _ _ ${AnsiColor.BRIGHT_YELLOW} ";
String prefix2 = "${AnsiColor.CYAN}/ ___|| |__ ___ _ _| | __| | ___ _ __ ${AnsiColor.BRIGHT_YELLOW} ";
String prefix3 = "${AnsiColor.CYAN}\\___ \\| '_ \\ / _ \\| | | | |/ _` |/ _ \\ '__|${AnsiColor.BRIGHT_YELLOW} ";
String prefix4 = "${AnsiColor.CYAN} ___) | | | | (_) | |_| | | (_| | __/ | ${AnsiColor.BRIGHT_YELLOW} ";
String prefix5 = "${AnsiColor.CYAN}|____/|_| |_|\\___/ \\__,_|_|\\__,_|\\___|_| ${AnsiColor.BRIGHT_YELLOW} ";
String suffix1 = "${AnsiColor.CYAN} __ __ __";
String suffix2 = "${AnsiColor.CYAN} \\ \\ \\ \\ \\ \\";
String suffix3 = "${AnsiColor.CYAN} \\ \\ \\ \\ \\ \\";
String suffix4 = "${AnsiColor.CYAN} / / / / / /";
String suffix5 = "${AnsiColor.CYAN} / / / / / /";
List<String> banner = List.of(origin.split("\n"));
// line1
System.out.print(prefix1);
System.out.print(banner.get(0));
System.out.println(suffix1);
// line2
System.out.print(prefix2);
System.out.print(banner.get(1));
System.out.println(suffix2);
// line3
System.out.print(prefix3);
System.out.print(banner.get(2));
System.out.println(suffix3);
// line4
System.out.print(prefix4);
System.out.print(banner.get(3));
System.out.println(suffix4);
// line5
System.out.print(prefix5);
System.out.print(banner.get(4));
System.out.println(suffix5);
// line6
printUnderLine(banner.get(5));
}
private static void printUnderLine(String line6){
String prefix6 = "${AnsiColor.CYAN}===========================================";
String suffix6 = "=/_/==/_/===/_/";
String pre = "${AnsiColor.BRIGHT_YELLOW}";
String suf = "${AnsiColor.CYAN}";
char[] chars = line6.toCharArray();
System.out.print(prefix6);
boolean noChar = true;
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if(c == ' '){
System.out.print(noChar ? "=" : "${AnsiColor.CYAN}=");
noChar = true;
}else {
System.out.print(noChar ? (pre + c) : c);
noChar = false;
}
}
System.out.println(suffix6);
}
}

View File

@@ -1,7 +1,7 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.controller;
package ${package}.start.controller;
import lombok.extern.shoulder.SLog;
import org.shoulder.core.log.Logger;
@@ -33,7 +33,8 @@ public class DemoController {
*/
@GetMapping("test")
public String test() {
return "this is a demo controller";
return "Congratulations on your new project based on <a href='https://github.com/ChinaLym/shoulder-platform'>shoulder-platform</a>!</br></br>" +
"恭喜你成功创建了一个基于<a href='https://github.com/ChinaLym/shoulder-platform'>shoulder-platform</a>的工程!";
}

View File

@@ -0,0 +1,18 @@
# 不对接注册中心时的配置文件参考
spring:
application:
name: @project.name@
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${MYSQL_ADDR:'127.0.0.1:3306'}/yourDataBaseName?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
username: root
password: ${MYSQL_PWD}
shoulder:
application:
id: ${spring.application.name}
errorCodePrefix: '0x000b' # unique code to mark a application

View File

@@ -9,3 +9,5 @@ ${AnsiColor.BLUE} :: Spring Boot :: ${AnsiColor.CYAN}${spring-boot
${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}
# http://patorjk.com/software/taag/#p=display&f=Ivrit&t=Shoulder-

View File

@@ -1,9 +1,11 @@
# 先从环境变量里取,若不存在,则以 maven 打包时的配置为准
# 使用 spring-cloud 注册中心时,使用如下配置即可,若不使用注册中心,删掉该文件即可
shoulder:
nacos:
ip: ${NACOS_IP:@nacos.ip@}
port: ${NACOS_PORT:@nacos.port@}
namespace: ${NACOS_ID:@nacos.namespace@}
ip: ${NACOS_IP:localhost} # 这里替换成自己的 nacos ip
port: ${NACOS_PORT:8848} # 这里替换成自己的 nacos port
namespace: ${NACOS_ID:} # 这里替换成自己的 namespace,默认空
# spring-boot-actuate 展示信息
info:
@@ -55,4 +57,4 @@ boot:
#password:
instance:
prefer-ip: true
service-url: localhost:8080
service-url: localhost:8080

View File

@@ -8,7 +8,9 @@
<modelVersion>4.0.0</modelVersion>
<name>${artifactId}</name>
<artifactId>${artifactId}</artifactId>
<description>todo 介绍以下这个工程</description>
<groupId>${groupId}</groupId>
<packaging>pom</packaging>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>cn.itlym</groupId>
<artifactId>shoulder-parent</artifactId>
<version>0.4-SNAPSHOT</version><!-- shoulder-version -->
<version>0.4</version><!-- shoulder-version -->
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -18,7 +18,7 @@
<properties>
<!-- =============== Shoulder 版本 =============== -->
<shoulder.version>0.4-SNAPSHOT</shoulder.version><!-- shoulder-version -->
<shoulder.version>0.4</shoulder.version><!-- shoulder-version -->
<shoulder-platform.version>1.0-SNAPSHOT</shoulder-platform.version><!-- shoulder-platform-version -->
<shoulder-sms-aliyun.version>1.0-SNAPSHOT</shoulder-sms-aliyun.version><!-- shoulder-sms-aliyun.version -->

View File

@@ -44,7 +44,7 @@
<!-- 数据库 连接池 默认使用高性能的 beecp (性能是 spring-boot 默认 hikairCP 两倍,功能较少)-->
<dependency>
<groupId>com.github.chris2018998</groupId>
<artifactId>BeeCP</artifactId>
<artifactId>beecp</artifactId>
</dependency>
<!-- beecp 的 starter 官方提供的有 bug 因为其 provide 属性会导致编译失败 -->
<!--<dependency>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>cn.itlym</groupId>
<artifactId>shoulder-parent</artifactId>
<version>0.4-SNAPSHOT</version><!-- shoulder-version -->
<version>0.4</version><!-- shoulder-version -->
</parent>
<modelVersion>4.0.0</modelVersion>