|
11 | 11 | import java.util.*; |
12 | 12 | import java.util.Map.Entry; |
13 | 13 | import java.util.stream.Collectors; |
| 14 | +import java.util.stream.Stream; |
14 | 15 | import javax.annotation.Nullable; |
15 | 16 | import org.springframework.beans.factory.ListableBeanFactory; |
16 | 17 | import org.springframework.beans.factory.NoUniqueBeanDefinitionException; |
@@ -96,6 +97,11 @@ static List<WorkerInterceptor> chooseWorkerInterceptors( |
96 | 97 | return workerInterceptor; |
97 | 98 | } |
98 | 99 |
|
| 100 | + /** |
| 101 | + * Create a comparator that can extract @Order and @Priority from beans in the given bean factory. |
| 102 | + * This is needed because the default OrderComparator doesn't know about the bean factory and |
| 103 | + * therefore can't look up annotations on beans. |
| 104 | + */ |
99 | 105 | private static Comparator<Object> beanFactoryAwareOrderComparator( |
100 | 106 | ListableBeanFactory beanFactory) { |
101 | 107 | return OrderComparator.INSTANCE.withSourceProvider( |
@@ -134,25 +140,22 @@ static <T> List<TemporalOptionsCustomizer<T>> chooseTemporalCustomizerBeans( |
134 | 140 | return null; |
135 | 141 | } |
136 | 142 | List<NonRootNamespaceProperties> nonRootNamespaceProperties = properties.getNamespaces(); |
137 | | - // If we only have one namespace (the root one), use all customizers |
138 | | - if (Objects.isNull(nonRootNamespaceProperties) || nonRootNamespaceProperties.isEmpty()) { |
139 | | - return customizerMap.entrySet().stream() |
140 | | - .sorted(beanFactoryAwareOrderComparator(beanFactory)) |
141 | | - .map(Entry::getValue) |
142 | | - .collect(Collectors.toList()); |
| 143 | + Stream<Entry<String, TemporalOptionsCustomizer<T>>> customizerStream = |
| 144 | + customizerMap.entrySet().stream(); |
| 145 | + if (!(Objects.isNull(nonRootNamespaceProperties) || nonRootNamespaceProperties.isEmpty())) { |
| 146 | + // Non-root namespace bean names, such as "nsWorkerFactoryCustomizer", "nsWorkerCustomizer" |
| 147 | + List<String> nonRootBeanNames = |
| 148 | + nonRootNamespaceProperties.stream() |
| 149 | + .map( |
| 150 | + ns -> |
| 151 | + temporalCustomizerBeanName( |
| 152 | + MoreObjects.firstNonNull(ns.getAlias(), ns.getNamespace()), |
| 153 | + genericOptionsBuilderClass)) |
| 154 | + .collect(Collectors.toList()); |
| 155 | + customizerStream = |
| 156 | + customizerStream.filter(entry -> !nonRootBeanNames.contains(entry.getKey())); |
143 | 157 | } |
144 | | - // Non-root namespace bean names, such as "nsWorkerFactoryCustomizer", "nsWorkerCustomizer" |
145 | | - List<String> nonRootBeanNames = |
146 | | - nonRootNamespaceProperties.stream() |
147 | | - .map( |
148 | | - ns -> |
149 | | - temporalCustomizerBeanName( |
150 | | - MoreObjects.firstNonNull(ns.getAlias(), ns.getNamespace()), |
151 | | - genericOptionsBuilderClass)) |
152 | | - .collect(Collectors.toList()); |
153 | | - |
154 | | - return customizerMap.entrySet().stream() |
155 | | - .filter(entry -> !nonRootBeanNames.contains(entry.getKey())) |
| 158 | + return customizerStream |
156 | 159 | .sorted(beanFactoryAwareOrderComparator(beanFactory)) |
157 | 160 | .map(Entry::getValue) |
158 | 161 | .collect(Collectors.toList()); |
|
0 commit comments