File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed
src/main/java/io/avaje/inject/core Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change 29
29
<version >1</version >
30
30
</dependency >
31
31
32
- <dependency >
33
- <groupId >javax.annotation</groupId >
34
- <artifactId >javax.annotation-api</artifactId >
35
- <version >1.3.2</version >
36
- </dependency >
37
-
38
32
<dependency >
39
33
<groupId >org.slf4j</groupId >
40
34
<artifactId >slf4j-api</artifactId >
Original file line number Diff line number Diff line change 5
5
import org .slf4j .Logger ;
6
6
import org .slf4j .LoggerFactory ;
7
7
8
- import javax . annotation .Priority ;
8
+ import java . lang . annotation .Annotation ;
9
9
import java .util .ArrayList ;
10
10
import java .util .Collections ;
11
11
import java .util .List ;
@@ -233,10 +233,20 @@ private static class SortBean<T> implements Comparable<SortBean<T>> {
233
233
}
234
234
235
235
int initPriority () {
236
- final Priority ann = bean .getClass ().getAnnotation (Priority .class );
237
- if (ann != null ) {
238
- priorityDefined = true ;
239
- return ann .value ();
236
+ // Avoid adding hard dependency on javax.annotation-api by using reflection to find @Priority
237
+ try {
238
+ Class <? extends Annotation > type = (Class <? extends Annotation >) Class .forName ("javax.annotation.Priority" );
239
+ Annotation ann = bean .getClass ().getAnnotation (type );
240
+ if (ann != null ) {
241
+ int priority = (Integer ) type .getMethod ("value" ).invoke (ann );
242
+ priorityDefined = true ;
243
+ return priority ;
244
+ }
245
+ } catch (ClassNotFoundException ignore ) {
246
+ // @Priority not available, so just use default priority
247
+ } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException | ExceptionInInitializerError | ClassCastException e ) {
248
+ // If this happens, something has gone very wrong since a non-confirming @Priority was found...
249
+ throw new UnsupportedOperationException ("Problem instantiating @Priority" , e );
240
250
}
241
251
// Default priority as per javax.ws.rs.Priorities.USER
242
252
// User-level filter/interceptor priority
You can’t perform that action at this time.
0 commit comments