From 75b89eec9dc33bff93ca2cd746eb7b46b41e9b41 Mon Sep 17 00:00:00 2001 From: Hollow Man Date: Fri, 7 Aug 2020 19:43:46 +0800 Subject: [PATCH] Get Spring context tutorial (#1342) --- .../case-get-spring-context-cn/arthas-boot.md | 16 ++++++ .../case-get-spring-context.md | 54 +++++++++++++++++++ .../case-get-spring-context-cn/finish.md | 10 ++++ .../case-get-spring-context-cn/index.json | 45 ++++++++++++++++ .../case-get-spring-context-cn/intro.md | 11 ++++ .../case-get-spring-context-cn/start-demo.md | 14 +++++ .../case-get-spring-context-en/arthas-boot.md | 16 ++++++ .../case-get-spring-context.md | 54 +++++++++++++++++++ .../case-get-spring-context-en/finish.md | 6 +++ .../case-get-spring-context-en/index.json | 45 ++++++++++++++++ .../case-get-spring-context-en/intro.md | 11 ++++ .../case-get-spring-context-en/start-demo.md | 14 +++++ 12 files changed, 296 insertions(+) create mode 100644 tutorials/katacoda/case-get-spring-context-cn/arthas-boot.md create mode 100644 tutorials/katacoda/case-get-spring-context-cn/case-get-spring-context.md create mode 100644 tutorials/katacoda/case-get-spring-context-cn/finish.md create mode 100644 tutorials/katacoda/case-get-spring-context-cn/index.json create mode 100644 tutorials/katacoda/case-get-spring-context-cn/intro.md create mode 100644 tutorials/katacoda/case-get-spring-context-cn/start-demo.md create mode 100644 tutorials/katacoda/case-get-spring-context-en/arthas-boot.md create mode 100644 tutorials/katacoda/case-get-spring-context-en/case-get-spring-context.md create mode 100644 tutorials/katacoda/case-get-spring-context-en/finish.md create mode 100644 tutorials/katacoda/case-get-spring-context-en/index.json create mode 100644 tutorials/katacoda/case-get-spring-context-en/intro.md create mode 100644 tutorials/katacoda/case-get-spring-context-en/start-demo.md diff --git a/tutorials/katacoda/case-get-spring-context-cn/arthas-boot.md b/tutorials/katacoda/case-get-spring-context-cn/arthas-boot.md new file mode 100644 index 000000000..84ef525a2 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: + +`wget https://alibaba.github.io/arthas/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 + +选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`: + +Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。 + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/case-get-spring-context-cn/case-get-spring-context.md b/tutorials/katacoda/case-get-spring-context-cn/case-get-spring-context.md new file mode 100644 index 000000000..1af555454 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/case-get-spring-context.md @@ -0,0 +1,54 @@ + + +在这个案例里,展示获取spring context,再获取bean,然后调用函数。 + +### 使用tt命令获取到spring context + +`tt`即 TimeTunnel,它可以记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测。 + +* https://alibaba.github.io/arthas/tt.html + +`tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod`{{execute T2}} + +访问:https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1 + +可以看到`tt`命令捕获到了一个请求: + +```bash +$ tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdaptePress Q or Ctrl+C to abort. +Affect(class-cnt:1 , method-cnt:1) cost in 252 ms. + INDE TIMESTAMP COST( IS-R IS- OBJECT CLASS METHOD + X ms) ET EXP +----------------------------------------------------------------------------------------- + 1000 2019-02-15 4.583 true fal 0xc93cf1a RequestMappingHand invokeHandlerMethod + 15:38:32 923 se lerAdapter +``` + +### 使用tt命令从调用记录里获取到spring context + +输入 `Q`{{execute T2}} 或者 `Ctrl + C` 退出上面的 `tt -t`命令。 + +`tt -i 1000 -w 'target.getApplicationContext()'`{{execute T2}} + +```bash +$ tt -i 1000 -w 'target.getApplicationContext()' +@AnnotationConfigEmbeddedWebApplicationContext[ + reader=@AnnotatedBeanDefinitionReader[org.springframework.context.annotation.AnnotatedBeanDefinitionReader@2e457641], + scanner=@ClassPathBeanDefinitionScanner[org.springframework.context.annotation.ClassPathBeanDefinitionScanner@6eb38026], + annotatedClasses=null, + basePackages=null, +] +Affect(row-cnt:1) cost in 439 ms. +``` + +## 获取spring bean,并调用函数 + +`tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()'`{{execute T2}} + +结果是: + +```bash +$ tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()' +@String[Hello World] +Affect(row-cnt:1) cost in 52 ms. +``` \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-cn/finish.md b/tutorials/katacoda/case-get-spring-context-cn/finish.md new file mode 100644 index 000000000..45436a4ea --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/finish.md @@ -0,0 +1,10 @@ + +通过本教程基本掌握了Arthas获取Spring Context。更多高级特性,可以在下面的进阶指南里继续了解。 + +* [Arthas进阶](https://alibaba.github.io/arthas/arthas-tutorials?language=cn&id=arthas-advanced) +* [Arthas Github](https://github.com/alibaba/arthas) +* [Arthas 文档](https://alibaba.github.io/arthas/) + +欢迎关注公众号,获取Arthas项目的信息,源码分析,案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/case-get-spring-context-cn/index.json b/tutorials/katacoda/case-get-spring-context-cn/index.json new file mode 100644 index 000000000..2692dfc75 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/index.json @@ -0,0 +1,45 @@ +{ + "title": "Arthas 获取Spring Context 案例", + "description": "Arthas 获取Spring Context 案例", + "difficulty": "高级使用者", + "time": "10分钟", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "获取Spring Context", + "text": "case-get-spring-context.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "java", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-cn/intro.md b/tutorials/katacoda/case-get-spring-context-cn/intro.md new file mode 100644 index 000000000..23669532b --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/intro.md @@ -0,0 +1,11 @@ + + + +![Arthas](https://alibaba.github.io/arthas/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + +`Arthas` 支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://alibaba.github.io/arthas/ \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-cn/start-demo.md b/tutorials/katacoda/case-get-spring-context-cn/start-demo.md new file mode 100644 index 000000000..59be66ea6 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-cn/start-demo.md @@ -0,0 +1,14 @@ + + + + +下载`demo-arthas-spring-boot.jar`,再用`java -jar`命令启动: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot`是一个很简单的spring boot应用,源代码:[查看](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +启动之后,可以访问80端口: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-en/arthas-boot.md b/tutorials/katacoda/case-get-spring-context-en/arthas-boot.md new file mode 100644 index 000000000..b9f9cc04f --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: + +`wget https://alibaba.github.io/arthas/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. + +Select the first process, type `1`{{execute T2}} ,then type `Enter`: + +After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help. + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/case-get-spring-context-en/case-get-spring-context.md b/tutorials/katacoda/case-get-spring-context-en/case-get-spring-context.md new file mode 100644 index 000000000..9ec2d125e --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/case-get-spring-context.md @@ -0,0 +1,54 @@ + + +In this case, the user can get the spring context, get the bean, and invoke the method. + +### Use the tt command to record the invocation of the specified method + +`tt` is TimeTunnel, which records the parameters and return value of each invocation of the specified method. + +* https://alibaba.github.io/arthas/tt.html + +`tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod`{{execute T2}} + +Visit: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/1 + +You can see that the `tt` command record an invocation: + +```bash +$ tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdaptePress Q or Ctrl+C to abort. +Affect(class-cnt:1 , method-cnt:1) cost in 252 ms. + INDE TIMESTAMP COST( IS-R IS- OBJECT CLASS METHOD + X ms) ET EXP +----------------------------------------------------------------------------------------- + 1000 2019-02-15 4.583 true fal 0xc93cf1a RequestMappingHand invokeHandlerMethod + 15:38:32 923 se lerAdapter +``` + +### Use the tt command to get the spring context from the invocation record. + +Type `Q`{{execute T2}} or `Ctrl + C` to exit the `tt -t` command above. + +`tt -i 1000 -w 'target.getApplicationContext()'`{{execute T2}} + +```bash +$ tt -i 1000 -w 'target.getApplicationContext()' +@AnnotationConfigEmbeddedWebApplicationContext[ + reader=@AnnotatedBeanDefinitionReader[org.springframework.context.annotation.AnnotatedBeanDefinitionReader@2e457641], + scanner=@ClassPathBeanDefinitionScanner[org.springframework.context.annotation.ClassPathBeanDefinitionScanner@6eb38026], + annotatedClasses=null, + basePackages=null, +] +Affect(row-cnt:1) cost in 439 ms. +``` + +## Get the spring bean and invoke method + +`tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()'`{{execute T2}} + +The result is: + +```bash +$ tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()' +@String[Hello World] +Affect(row-cnt:1) cost in 52 ms. +``` \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-en/finish.md b/tutorials/katacoda/case-get-spring-context-en/finish.md new file mode 100644 index 000000000..f3a127734 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/finish.md @@ -0,0 +1,6 @@ + +Through this tutorial, you can know how to Get the Spring Context. More advanced features can be found in the Advanced Guide below. + +* [Arthas Advanced](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=arthas-advanced) +* [Arthas Github](https://github.com/alibaba/arthas) +* [Arthas Documentation](https://alibaba.github.io/arthas/en) diff --git a/tutorials/katacoda/case-get-spring-context-en/index.json b/tutorials/katacoda/case-get-spring-context-en/index.json new file mode 100644 index 000000000..fc8a51f57 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/index.json @@ -0,0 +1,45 @@ +{ + "title": "Arthas Get the Spring Context", + "description": "Arthas Get the Spring Context", + "difficulty": "expert", + "time": "10 minutes", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "Get the Spring Context", + "text": "case-get-spring-context.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "java", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-en/intro.md b/tutorials/katacoda/case-get-spring-context-en/intro.md new file mode 100644 index 000000000..e45235726 --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/intro.md @@ -0,0 +1,11 @@ + + + +![Arthas](https://alibaba.github.io/arthas/_images/arthas.png) + +`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers. + +`Arthas` supports JDK 6+, supports Linux/Mac/Windows. + +* Github: https://github.com/alibaba/arthas +* Documentation: https://alibaba.github.io/arthas/en \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-en/start-demo.md b/tutorials/katacoda/case-get-spring-context-en/start-demo.md new file mode 100644 index 000000000..4915b847a --- /dev/null +++ b/tutorials/katacoda/case-get-spring-context-en/start-demo.md @@ -0,0 +1,14 @@ + + + + +Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file