Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch Spring context invoke method field #5

Closed
WangJi92 opened this issue Mar 21, 2020 · 1 comment
Closed

Watch Spring context invoke method field #5

WangJi92 opened this issue Mar 21, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@WangJi92
Copy link
Owner

WangJi92 commented Mar 21, 2020

Watch Spring Context Invoke Method Field 命令

右键选择需要调用的spring bean 的方法或者 字段的信息
image

获取命令

image
没有错,这个和 Static spring context invoke method field 一样的,只是这里的获取spring context的路径不一样,这里通过watch 去获取spring context ** watch 必须要被触发一次才能进行调用哦**

watch -x 3 -n 3  org.springframework.web.servlet.DispatcherServlet doDispatch '@org.springframework.web.context.support.WebApplicationContextUtils@getWebApplicationContext(params[0].getServletContext()).getBean("controllerTest").test()'

image
触发调用一下这个接口,必须要触发一下接口的调用,任意接口都可以,由于这里watch的是org.springframework.web.servlet.DispatcherServlet doDispatch 因此都可以
image
image
效果如下
image

help watch

the content you want to watch, written by ognl. 由于这里是被ognl 处理的,所以可以支持ognl的表达式去处理哦。

[arthas@21289]$ help watch
 USAGE:
   watch [-b] [-e] [-x <value>] [-f] [-h] [-n <value>] [-E] [-M <value>] [-s] class-pattern method-pattern
 express [condition-express]

 SUMMARY:
   Display the input/output parameter, return object, and thrown exception of specified method invocation
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 Examples:
   watch -b org.apache.commons.lang.StringUtils isBlank params
   watch -f org.apache.commons.lang.StringUtils isBlank returnObj
   watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj}' -x 2
   watch -bf *StringUtils isBlank params
   watch *StringUtils isBlank params[0]
   watch *StringUtils isBlank params[0] params[0].length==1
   watch *StringUtils isBlank params '#cost>100'
   watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]

 WIKI:
   https://alibaba.github.io/arthas/watch

 OPTIONS:
 -b, --before                        Watch before invocation
 -e, --exception                     Watch after throw exception
 -x, --expand <value>                Expand level of object (1 by default)
 -f, --finish                        Watch after invocation, enable by default
 -h, --help                          this help
 -n, --limits <value>                Threshold of execution times
 -E, --regex                         Enable regular expression to match (wildcard matching by default)
 -M, --sizeLimit <value>             Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
 -s, --success                       Watch after successful invocation
 <class-pattern>                     The full qualified class name you want to watch
 <method-pattern>                    The method name you want to watch
 <express>                           the content you want to watch, written by ognl.
                                     Examples:
                                       params
                                       params[0]
                                       'params[0]+params[1]'
                                       '{params[0], target, returnObj}'
                                       returnObj
                                       throwExp
                                       target
                                       clazz
                                       method

 <condition-express>                 Conditional expression in ognl style, for example:
                                       TRUE  : 1==1
                                       TRUE  : true
                                       FALSE : false
                                       TRUE  : 'params.length>=0'
                                       FALSE : 1==2

可以参考学习的网址

ognl 官方
ognl 特殊用法
ognl 最佳实践

other

这里watch的是接口的分发的入口类,一般只要watch 执行 ognl的spring context 表达式都会成功的,调用方法要注意安全哦。

@WangJi92 WangJi92 added the documentation Improvements or additions to documentation label Mar 22, 2020
@WangJi92
Copy link
Owner Author

WangJi92 commented Jun 20, 2020

watch 可以直接调用ognl 表达式,当前就是利用了 通过获取静态的方法获取到spring 的application context 的值而已 获取分布式跟踪的 traceId 这个也是通过利用这个特性来获取值的。

watch com.test.pandora.eagleeye.HomeController home '@com.taobao.eagleeye.EagleEye@getTraceId()'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant