我正在开发一个基于Spring Shell的程序,该程序需要自定义ResultHandler。 因此,我尝试定义一个返回ResultHandler的bean,然后发生如下所示的错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'utilCommands': Unsatisfied dependency expressed through field 'shell'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shell' defined in class path resource [org/springframework/shell/SpringShellAutoConfiguration.class]: Unsatisfied dependency expressed through method 'shell' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.shell.result.ResultHandlerConfig': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainResultHandler': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Multiple ResultHandlers configured for class java.lang.Object: both org.springframework.shell.result.DefaultResultHandler@ba8773 and org.springframework.shell.result.DefaultResultHandler@1176a31
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shell' defined in class path resource [org/springframework/shell/SpringShellAutoConfiguration.class]: Unsatisfied dependency expressed through method 'shell' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.shell.result.ResultHandlerConfig': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainResultHandler': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Multiple ResultHandlers configured for class java.lang.Object: both org.springframework.shell.result.DefaultResultHandler@ba8773 and org.springframework.shell.result.DefaultResultHandler@1176a31
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.shell.result.ResultHandlerConfig': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainResultHandler': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Multiple ResultHandlers configured for class java.lang.Object: both org.springframework.shell.result.DefaultResultHandler@ba8773 and org.springframework.shell.result.DefaultResultHandler@1176a31
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainResultHandler': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Multiple ResultHandlers configured for class java.lang.Object: both org.springframework.shell.result.DefaultResultHandler@ba8773 and org.springframework.shell.result.DefaultResultHandler@1176a31
Caused by: java.lang.IllegalArgumentException: Multiple ResultHandlers configured for class java.lang.Object: both org.springframework.shell.result.DefaultResultHandler@ba8773 and org.springframework.shell.result.DefaultResultHandler@1176a31
因此,我尝试使用SprintBootApplication批注的exclude属性排除扫描org.springframework.shell.result.ResultHandlerConfig。但是它失败,并显示以下错误消息:
java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes:
- org.springframework.shell.result.ResultHandlerConfig
我怎么了?如何将自定义ResultHandler应用于Spring Shell?