@@ -116,9 +116,9 @@ public RouterSpec<K, R> suffix(String suffix) {
116
116
* @return the router spec.
117
117
* @see AbstractMappingMessageRouter#setChannelMapping(String, String)
118
118
*/
119
- public RouterSpec <K , R > channelMapping (K key , final String channelName ) {
119
+ public RouterSpec <K , R > channelMapping (K key , String channelName ) {
120
120
Assert .notNull (key , "'key' must not be null" );
121
- Assert .hasText (channelName , "'channelName' must not be null " );
121
+ Assert .hasText (channelName , "'channelName' must not be empty " );
122
122
if (key instanceof String ) {
123
123
this .handler .setChannelMapping ((String ) key , channelName );
124
124
}
@@ -140,6 +140,26 @@ public String getComponentType() {
140
140
return _this ();
141
141
}
142
142
143
+ /**
144
+ * The router mapping configuration based on the provided generic key
145
+ * and {@link MessageChannel} bean.
146
+ * The {@link MessageChannel} must be instance of {@link NamedComponent}
147
+ * for proper target router mapping based on the bean name.
148
+ * @param key the key.
149
+ * @param channel the {@link MessageChannel} instance to use.
150
+ * @return the router spec.
151
+ * @see AbstractMappingMessageRouter#setChannelMapping(String, String)
152
+ * @since 5.2
153
+ */
154
+ public RouterSpec <K , R > channelMapping (K key , final MessageChannel channel ) {
155
+ Assert .notNull (key , "'key' must not be null" );
156
+ Assert .notNull (channel , "'channel' must not be null" );
157
+ Assert .isInstanceOf (NamedComponent .class , channel ,
158
+ () -> "The routing channel '" + channel + " must be instance of 'NamedComponent'." );
159
+ this .mappingProvider .addMapping (key , (NamedComponent ) channel );
160
+ return _this ();
161
+ }
162
+
143
163
/**
144
164
* Add a subflow as an alternative to a {@link #channelMapping(Object, String)}.
145
165
* {@link #prefix(String)} and {@link #suffix(String)} cannot be used when subflow
0 commit comments