目标:
1.运行soul-admin工程日志分析
1.1在配置了mysql地址和用户名、密码后,启动成功。在启动日志中会发现有如下信息:
Thu Jan 14 14:46:36 CST 2021 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
提示信息说明的很清楚,在mysql 5.7版本数据库链接字符串中需要添加ssl的设置。在配置文件中找到相应的配置并添加。如下所示:
datasource:
url: jdbc:mysql://localhost:3306/soul?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
再次启动后没有提示了。
PS:在mysql 5.7 任何数据库连接最好添加这个参数设置
1.2初始化数据库:
2021-01-14 14:55:24.289 INFO 14844 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1654 ms
2021-01-14 14:55:24.702 INFO 14844 --- [ main] o.d.s.a.s.init.LocalDataSourceLoader : execute soul schema sql: META-INF/schema.sql
开始数据库中并没有创建soul要使用库和表,所以这里日志中打印出LocalDataSourceLoader中会执行schema.sql文件。每次启动都会去执行这个脚本。脚本中的执行语句是进行了判断,如果存在就不执行。但是需要注意:脚本中的insert 语句执行结果不会插入数据,数据库会反馈
Duplicate entry '1' for key 'PRIMARY'
1.3AutowiredAnnotationBeanPostProcessor:
接下来日志中大量的出现AutowiredAnnotationBeanPostProcessor
2021-01-14 14:55:25.285 INFO 14844 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : Inconsistent constructor declaration on bean with name 'appAuthController': single autowire-marked constructor flagged as optional - this constructor is effectively required since there is no default constructor to fall back to: public org.dromara.soul.admin.controller.AppAuthController(org.dromara.soul.admin.service.AppAuthService)
根据这段日志说明,名为“appAuthController”的bean上的构造函数声明不一致:单个autowire标记的构造函数被标记为可选的-此构造函数实际上是必需的,因为没有可回退到的默认构造函数。
public class AppAuthController {
private final AppAuthService appAuthService;
/**
* Instantiates a new App auth controller.
*
* @param appAuthService the app auth service
*/
@Autowired(required = false)
public AppAuthController(final AppAuthService appAuthService) {
this.appAuthService = appAuthService;
这样写的目的是什么?和以下代码的区别是什么?
@Autowired
private AppAuthService appAuthService;
1.4 使用HikariPool作为数据连接池
2021-01-14 14:55:25.827 INFO 14844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-01-14 14:55:25.842 INFO 14844 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
这里使用了spring boot 默认的数据库连接池
1.5 工程中使用了actuator插件
2021-01-14 14:55:26.262 INFO 14844 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
说明soul-admin开启了actuator监控。actuator的配置在哪里呢?
1.6 工程启动了swagger 在线文档
2021-01-14 14:55:26.440 INFO 14844 --- [ main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2Controller#getDocumentation(String, HttpServletRequest)]
访问http://localhost:9095/swagger-ui.html 可以查看API情况。系统没有登录的情况下也可以访问到swagger。如果正式环境部署的话,会存在安全问题。正式环境需要将swagger屏蔽。
1.7 加载欢迎界面
2021-01-14 14:55:26.684 INFO 14844 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
1.8 启动完成
2021-01-14 14:55:27.375 INFO 14844 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9095 (http) with context path ''
2.运行soul-bootstrap工程日志分析
2.1 打印soul的logo
2021-01-14 23:02:33.998 INFO 22028 --- [ main] org.dromara.soul.web.logo.SoulLogo :
这个类实现了ApplicationListener接口。
@Order(LoggingApplicationListener.DEFAULT_ORDER + 1)
@Slf4j
public class SoulLogo implements ApplicationListener {
private static final String SOUL_LOGO = "\n"
+ " _ \n"
+ " | | \n"
+ " ___ ___ _ _| | \n"
+ "/ __|/ _ \\| | | | |\n"
+ "\\__ \\ (_) | |_| | |\n"
+ "|___/\\___/ \\__,_|_|\n"
+ " \n"
+ " \n";
private final AtomicBoolean alreadyLog = new AtomicBoolean(false);
@Override
public void onApplicationEvent(final ApplicationEnvironmentPreparedEvent event) {
if (!alreadyLog.compareAndSet(false, true)) {
return;
}
log.info(buildBannerText());
在这里实现了Logo的打印。这里提供给我们一个自定义logo的方式。
2.2 加载插件
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[global] [org.dromara.soul.plugin.global.GlobalPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[sign] [org.dromara.soul.plugin.sign.SignPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[waf] [org.dromara.soul.plugin.waf.WafPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[rate_limiter] [org.dromara.soul.plugin.ratelimiter.RateLimiterPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[hystrix] [org.dromara.soul.plugin.hystrix.HystrixPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[resilience4j] [org.dromara.soul.plugin.resilience4j.Resilience4JPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[divide] [org.dromara.soul.plugin.divide.DividePlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[webClient] [org.dromara.soul.plugin.httpclient.WebClientPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[divide] [org.dromara.soul.plugin.divide.websocket.WebSocketPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[alibaba-dubbo-body-param] [org.dromara.soul.plugin.alibaba.dubbo.param.BodyParamPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[dubbo] [org.dromara.soul.plugin.alibaba.dubbo.AlibabaDubboPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[monitor] [org.dromara.soul.plugin.monitor.MonitorPlugin]
2021-01-14 23:02:36.638 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[response] [org.dromara.soul.plugin.httpclient.response.WebClientResponsePlugin]
2021-01-14 23:02:36.639 INFO 22028 --- [ main] o.d.s.w.configuration.SoulConfiguration : load plugin:[response] [org.dromara.soul.plugin.alibaba.dubbo.response.DubboResponsePlugin]
这里在第一次浏览不知道是如何加载的~~
2.3 使用websocket 去和soul-admin进行连接
2021-01-14 23:03:18.902 INFO 22028 --- [ocket-connect-1] o.d.s.p.s.d.w.WebsocketSyncDataService : websocket reconnect is successful.....
为什么使用websocket去连接admin。设计思想是什么?
2.4 工程中使用了actuator插件
2021-01-14 23:02:38.902 INFO 22028 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
这里通过连接无法访问actuator。 当设置成true 时,需要连接redis 。没有redis 的话会出现异常。PS: 在浏览器上访问http://localhost:9195/actuator 实际上会转发给配置的服务,然后把后端服务的信息返回。我启动后没有配置后端服务,返回的信息如下:
{"code":-107,"message":"Can not find selector, please check your configuration!","data":null}
日志显示:
2021-01-14 23:28:11.471 ERROR 13280 --- [-work-threads-1] o.d.soul.plugin.base.utils.CheckUtils : can not match selector data: divide
2.5 netty 服务启动成功
2021-01-14 23:02:39.734 INFO 22028 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 9195
这里信息说明spring boot 使用netty 方式启动的。一般没有配置默认使用的是tomcat 作为容器启动的。
3.思考:
4.总结: