File tree 3 files changed +22
-3
lines changed
spring-shell-core/src/main/java/org/springframework/shell
spring-shell-docs/src/main/asciidoc
3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2022 the original author or authors.
2
+ * Copyright 2022-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .shell .command ;
17
17
18
+ import org .springframework .core .Ordered ;
19
+ import org .springframework .core .annotation .Order ;
20
+
18
21
/**
19
22
* Interface to be implemented by objects that can resolve exceptions thrown
20
23
* during command processing, in the typical case error response. Implementors
25
28
*/
26
29
public interface CommandExceptionResolver {
27
30
31
+ /**
32
+ * Default precedence related use of {@link Ordered} and {@link Order}.
33
+ */
34
+ int DEFAULT_PRECEDENCE = -100 ;
35
+
28
36
/**
29
37
* Try to resolve the given exception that got thrown during command processing.
30
38
*
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2017-2022 the original author or authors.
2
+ * Copyright 2017-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
22
22
import org .springframework .context .annotation .Bean ;
23
23
import org .springframework .context .annotation .Configuration ;
24
+ import org .springframework .core .annotation .Order ;
24
25
import org .springframework .shell .TerminalSizeAware ;
25
26
import org .springframework .shell .command .CommandCatalog ;
27
+ import org .springframework .shell .command .CommandExceptionResolver ;
26
28
import org .springframework .shell .command .CommandParserExceptionResolver ;
27
29
import org .springframework .shell .context .ShellContext ;
28
30
import org .springframework .shell .jline .InteractiveShellRunner ;
33
35
* @author Eric Bottard
34
36
* @author Janne Valkealahti
35
37
*/
36
- @ Configuration
38
+ @ Configuration ( proxyBeanMethods = false )
37
39
public class ResultHandlerConfig {
38
40
39
41
@ Bean
@@ -58,6 +60,7 @@ public ParameterValidationExceptionResultHandler parameterValidationExceptionRes
58
60
}
59
61
60
62
@ Bean
63
+ @ Order (CommandExceptionResolver .DEFAULT_PRECEDENCE )
61
64
public CommandParserExceptionResolver commandParserExceptionResolver () {
62
65
return new CommandParserExceptionResolver ();
63
66
}
Original file line number Diff line number Diff line change @@ -45,3 +45,11 @@ you want to define exit code there.
45
45
include::{snippets}/ErrorHandlingSnippets.java[tag=my-exception-class]
46
46
----
47
47
====
48
+
49
+ Some build in `CommandExceptionResolver` beans are registered to handle common
50
+ exceptions thrown from command parsing. These are registered with _order_
51
+ presedence defined in `CommandExceptionResolver.DEFAULT_PRECEDENCE`.
52
+ As these beans are used in a given order, `@Order` annotation or `Ordered`
53
+ interface from can be used just like in any other spring app. This
54
+ is generally useful if you need to control your own beans to get used
55
+ either before or after a defaults.
You can’t perform that action at this time.
0 commit comments