Reputation: 41261
In the Spring-boot remote shell, CRaSH, I can dump all the Spring beans to the screen in what looks like 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
... etc
But I can't find a way to filter that output:
beans | filter -p bean:repositoryServer
I see from the internal "man" page that the beans
command produces Object, and filter
consumes Map
, so the failure makes sense.
How can I get info about a single bean from the CRaSH shell?
Upvotes: 0
Views: 521
Reputation: 1757
Put this in a file under /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)
}
};
}
}
You can the use it to find beans by name like
beans | bfilter .*Endpoint
or just find a single bean
beans | bfilter application
Upvotes: 3