mirror of https://github.com/alibaba/arthas.git
Get Spring context tutorial (#1342)
parent
93be862c20
commit
75b89eec9d
@ -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"
|
||||||
|
}
|
||||||
|
}
|
@ -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.
|
||||||
|
```
|
@ -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)
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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)
|
Loading…
Reference in New Issue