Skip to content

Commit

Permalink
GH-106: Fix SplitterFunctionConfiguration for ambiguity on auto-wiring
Browse files Browse the repository at this point in the history
Fixes: #106

The `AbstractMessageSplitter messageSplitter` injection is too wide,
and if target application has its own splitter bean, it becomes as a candidate.
Since `SplitterFunctionConfiguration` expects only its own beans, rework the logic for `@Qualifier`
and `Optional` to be explicit for expected beans from the `SplitterFunctionConfiguration`.
  • Loading branch information
artembilan committed Dec 6, 2024
1 parent 3f041a9 commit 58ffb22
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import java.nio.charset.Charset;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -49,9 +51,15 @@
public class SplitterFunctionConfiguration {

@Bean
public Function<Message<?>, List<Message<?>>> splitterFunction(AbstractMessageSplitter messageSplitter,
public Function<Message<?>, List<Message<?>>> splitterFunction(
@Qualifier("expressionSplitter") Optional<AbstractMessageSplitter> expressionSplitter,
@Qualifier("fileSplitter") Optional<AbstractMessageSplitter> fileSplitter,
@Qualifier("defaultSplitter") Optional<AbstractMessageSplitter> defaultSplitter,
SplitterFunctionProperties splitterFunctionProperties) {

AbstractMessageSplitter messageSplitter = expressionSplitter.or(() -> fileSplitter)
.or(() -> defaultSplitter)
.get();
messageSplitter.setApplySequence(splitterFunctionProperties.isApplySequence());
ThreadLocalFluxSinkMessageChannel outputChannel = new ThreadLocalFluxSinkMessageChannel();
messageSplitter.setOutputChannel(outputChannel);
Expand Down

0 comments on commit 58ffb22

Please sign in to comment.