39
39
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
40
40
import org .springframework .beans .factory .support .BeanDefinitionOverrideException ;
41
41
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
42
+ import org .springframework .beans .factory .support .RootBeanDefinition ;
42
43
import org .springframework .context .ApplicationContext ;
43
44
import org .springframework .context .ApplicationContextAware ;
44
45
import org .springframework .context .ApplicationEventPublisherAware ;
48
49
import org .springframework .context .MessageSourceAware ;
49
50
import org .springframework .context .ResourceLoaderAware ;
50
51
import org .springframework .context .SmartLifecycle ;
52
+ import org .springframework .core .ResolvableType ;
51
53
import org .springframework .core .io .DescriptiveResource ;
52
54
import org .springframework .core .type .MethodMetadata ;
53
55
import org .springframework .integration .channel .AbstractMessageChannel ;
@@ -153,8 +155,7 @@ private Object processStandardIntegrationFlow(StandardIntegrationFlow flow, Stri
153
155
154
156
for (Map .Entry <Object , String > entry : integrationComponents .entrySet ()) {
155
157
Object component = entry .getKey ();
156
- if (component instanceof ConsumerEndpointSpec ) {
157
- ConsumerEndpointSpec <?, ?> endpointSpec = (ConsumerEndpointSpec <?, ?>) component ;
158
+ if (component instanceof ConsumerEndpointSpec <?, ?> endpointSpec ) {
158
159
MessageHandler messageHandler = endpointSpec .get ().getT2 ();
159
160
ConsumerEndpointFactoryBean endpoint = endpointSpec .get ().getT1 ();
160
161
String id = endpointSpec .getId ();
@@ -184,8 +185,7 @@ else if (component instanceof MessageChannelReference) {
184
185
targetIntegrationComponents .put (directChannel , channelBeanName );
185
186
}
186
187
}
187
- else if (component instanceof SourcePollingChannelAdapterSpec ) {
188
- SourcePollingChannelAdapterSpec spec = (SourcePollingChannelAdapterSpec ) component ;
188
+ else if (component instanceof SourcePollingChannelAdapterSpec spec ) {
189
189
Map <Object , String > componentsToRegister = spec .getComponentsToRegister ();
190
190
if (!CollectionUtils .isEmpty (componentsToRegister )) {
191
191
componentsToRegister .entrySet ()
@@ -233,8 +233,7 @@ else if (useFlowIdAsPrefix) {
233
233
registerComponent (component , channelBeanName , flowBeanName );
234
234
targetIntegrationComponents .put (component , channelBeanName );
235
235
}
236
- else if (component instanceof FixedSubscriberChannel ) {
237
- FixedSubscriberChannel fixedSubscriberChannel = (FixedSubscriberChannel ) component ;
236
+ else if (component instanceof FixedSubscriberChannel fixedSubscriberChannel ) {
238
237
String channelBeanName = fixedSubscriberChannel .getComponentName ();
239
238
if ("Unnamed fixed subscriber channel" .equals (channelBeanName )) {
240
239
channelBeanName = flowNamePrefix + "channel" +
@@ -263,8 +262,14 @@ else if (component instanceof AnnotationGatewayProxyFactoryBean<?> gateway) {
263
262
}
264
263
265
264
registerComponent (gateway , gatewayId , flowBeanName ,
266
- beanDefinition -> ((AbstractBeanDefinition ) beanDefinition )
267
- .setSource (new DescriptiveResource ("" + gateway .getObjectType ())));
265
+ beanDefinition -> {
266
+ RootBeanDefinition definition = (RootBeanDefinition ) beanDefinition ;
267
+ Class <?> serviceInterface = gateway .getObjectType ();
268
+ definition .setSource (new DescriptiveResource ("" + serviceInterface ));
269
+ definition .setTargetType (
270
+ ResolvableType .forClassWithGenerics (AnnotationGatewayProxyFactoryBean .class ,
271
+ serviceInterface ));
272
+ });
268
273
269
274
targetIntegrationComponents .put (component , gatewayId );
270
275
}
@@ -341,10 +346,9 @@ private void processIntegrationComponentSpec(String beanName, IntegrationCompone
341
346
342
347
invokeBeanInitializationHooks (beanName , target );
343
348
344
- if (bean instanceof ComponentsRegistration ) {
345
- Map <Object , String > componentsToRegister = (( ComponentsRegistration ) bean ) .getComponentsToRegister ();
349
+ if (bean instanceof ComponentsRegistration componentsRegistration ) {
350
+ Map <Object , String > componentsToRegister = componentsRegistration .getComponentsToRegister ();
346
351
if (!CollectionUtils .isEmpty (componentsToRegister )) {
347
-
348
352
componentsToRegister .entrySet ()
349
353
.stream ()
350
354
.filter (component -> noBeanPresentForComponent (component .getKey (), beanName ))
@@ -358,40 +362,42 @@ private void processIntegrationComponentSpec(String beanName, IntegrationCompone
358
362
359
363
private void invokeBeanInitializationHooks (final String beanName , final Object bean ) { // NOSONAR complexity
360
364
if (bean instanceof Aware ) {
361
- if (bean instanceof BeanNameAware ) {
362
- (( BeanNameAware ) bean ) .setBeanName (beanName );
365
+ if (bean instanceof BeanNameAware beanNameAware ) {
366
+ beanNameAware .setBeanName (beanName );
363
367
}
364
- if (bean instanceof BeanClassLoaderAware && this .beanFactory .getBeanClassLoader () != null ) {
365
- ((BeanClassLoaderAware ) bean ).setBeanClassLoader (this .beanFactory .getBeanClassLoader ()); // NOSONAR
368
+ if (bean instanceof BeanClassLoaderAware beanClassLoaderAware
369
+ && this .beanFactory .getBeanClassLoader () != null ) {
370
+
371
+ beanClassLoaderAware .setBeanClassLoader (this .beanFactory .getBeanClassLoader ()); // NOSONAR
366
372
}
367
- if (bean instanceof BeanFactoryAware ) {
368
- (( BeanFactoryAware ) bean ) .setBeanFactory (this .beanFactory );
373
+ if (bean instanceof BeanFactoryAware beanFactoryAware ) {
374
+ beanFactoryAware .setBeanFactory (this .beanFactory );
369
375
}
370
- if (bean instanceof EnvironmentAware ) {
371
- (( EnvironmentAware ) bean ) .setEnvironment (this .applicationContext .getEnvironment ());
376
+ if (bean instanceof EnvironmentAware environmentAware ) {
377
+ environmentAware .setEnvironment (this .applicationContext .getEnvironment ());
372
378
}
373
- if (bean instanceof EmbeddedValueResolverAware ) {
374
- (( EmbeddedValueResolverAware ) bean ) .setEmbeddedValueResolver (this .embeddedValueResolver );
379
+ if (bean instanceof EmbeddedValueResolverAware embeddedValueResolverAware ) {
380
+ embeddedValueResolverAware .setEmbeddedValueResolver (this .embeddedValueResolver );
375
381
}
376
- if (bean instanceof ResourceLoaderAware ) {
377
- (( ResourceLoaderAware ) bean ) .setResourceLoader (this .applicationContext );
382
+ if (bean instanceof ResourceLoaderAware resourceLoaderAware ) {
383
+ resourceLoaderAware .setResourceLoader (this .applicationContext );
378
384
}
379
- if (bean instanceof ApplicationEventPublisherAware ) {
380
- (( ApplicationEventPublisherAware ) bean ) .setApplicationEventPublisher (this .applicationContext );
385
+ if (bean instanceof ApplicationEventPublisherAware eventPublisherAware ) {
386
+ eventPublisherAware .setApplicationEventPublisher (this .applicationContext );
381
387
}
382
- if (bean instanceof MessageSourceAware ) {
383
- (( MessageSourceAware ) bean ) .setMessageSource (this .applicationContext );
388
+ if (bean instanceof MessageSourceAware messageSourceAware ) {
389
+ messageSourceAware .setMessageSource (this .applicationContext );
384
390
}
385
- if (bean instanceof ApplicationContextAware ) {
386
- (( ApplicationContextAware ) bean ) .setApplicationContext (this .applicationContext );
391
+ if (bean instanceof ApplicationContextAware applicationContextAware ) {
392
+ applicationContextAware .setApplicationContext (this .applicationContext );
387
393
}
388
394
}
389
395
}
390
396
391
397
@ SuppressWarnings ("unchecked" )
392
398
private boolean noBeanPresentForComponent (Object instance , String parentBeanName ) {
393
- if (instance instanceof NamedComponent ) {
394
- String beanName = (( NamedComponent ) instance ) .getBeanName ();
399
+ if (instance instanceof NamedComponent namedComponent ) {
400
+ String beanName = namedComponent .getBeanName ();
395
401
if (beanName == null || !this .beanFactory .containsBean (beanName )) {
396
402
return true ;
397
403
}
@@ -455,8 +461,8 @@ private String generateBeanName(Object instance, String prefix) {
455
461
}
456
462
457
463
private String generateBeanName (Object instance , String prefix , String fallbackId , boolean useFlowIdAsPrefix ) {
458
- if (instance instanceof NamedComponent && (( NamedComponent ) instance ) .getBeanName () != null ) {
459
- String beanName = (( NamedComponent ) instance ) .getBeanName ();
464
+ if (instance instanceof NamedComponent namedComponent && namedComponent .getBeanName () != null ) {
465
+ String beanName = namedComponent .getBeanName ();
460
466
return useFlowIdAsPrefix
461
467
? prefix + beanName
462
468
: beanName ;
@@ -468,8 +474,8 @@ else if (fallbackId != null) {
468
474
}
469
475
470
476
String generatedBeanName = prefix ;
471
- if (instance instanceof NamedComponent ) {
472
- generatedBeanName += (( NamedComponent ) instance ) .getComponentType ();
477
+ if (instance instanceof NamedComponent namedComponent ) {
478
+ generatedBeanName += namedComponent .getComponentType ();
473
479
}
474
480
else {
475
481
generatedBeanName += instance .getClass ().getName ();
0 commit comments