簡體   English   中英

在CRaSH Shell中過濾Spring bean(Spring Boot遠程Shell)

[英]Filter Spring beans in CRaSH shell (Spring-boot remote shell)

在Spring-boot遠程外殼CRaSH中,我可以將所有Spring Bean以類似於JSON的形式轉儲到屏幕上:

 > beans
 [{context=application, parent=null, beans=[{bean=repositoryServer, scope=singleton,
  type=com.opentext.tlsPolicyRepository.RepositoryServer$$EnhancerBySpringCGLIB$$841a12c7, 
 resource=null, dependencies=[]}, {bean=tlsPolicyRepositoryController,
 scope=singleton, type=com.opentext.tlsPolicyRepository.TlsPolicyRepositoryController,
 resource=file 

...等等

但是我找不到過濾該輸出的方法:

 beans | filter -p bean:repositoryServer

我從內部的“ man”頁面中看到, beans命令產生Object,而filter消耗Map ,所以失敗是有道理的。

如何從CRaSH Shell中獲取有關單個bean的信息?

將其放在/src/main/resources/commands/bfilter.groovy下的文件中

import org.crsh.cli.Command;
import org.crsh.cli.Usage;
import org.crsh.command.Pipe;
import org.crsh.cli.Argument;

class bfilter {
 @Usage("Filters output of beans")
    @Command
    Pipe<Object,Object> main(
    @Usage("regex of bean names to find")
    @Argument String regex) {
        return new Pipe<Object, Object>(){
            public void provide(Object result) {
                def bean = []
                for(entry in result){
                    for(aBean in entry.beans){
                        if(aBean.bean.matches(regex)){
                            bean << aBean
                        }
                    }

                }
                context.provide(bean)
            }
        };
    }
}

您可以使用它來按名稱查找咖啡豆,例如

beans | bfilter .*Endpoint

或只是找到一個豆

beans | bfilter application

資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM