INT-3916: Don't Use CTOR Injection in FactoryBean

JIRA: https://jira.spring.io/browse/INT-3916

The `JpaOutboundGatewayFactoryBean` used CTOR injection for the `JpaExecutor`.
That one, in turn, uses CTOR injection for the `EntityManagerFactory`.

Such a dependency may cause the `early bean instantiating` in case of `AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck()`.
And we end up with the `BeanCurrentlyInCreationException`.

Therefore no one `FactoryBean` should use CTOR injection if there is a potential hierarchical dependency.

NOTE: there is no tests on the matter, since we don't change the components behavior.
The `JPA` sample application will be changed to the Boot to track this fix.

**Cherry-pick to 4.2.x**

Address PR comments and fix other `FactoryBean`s for the same issue, when it is reasonable

Polishing

Address PR comments

Make setter `setSockJsTaskScheduler` as `public`

Conflicts:
	spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java
	spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBean.java
	spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests-context.xml
	spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/XmppConnectionFactoryBeanTests.java
This commit is contained in:
Artem Bilan
2015-12-17 18:05:31 -05:00
parent 588ccdbb00
commit 09289fc08d
15 changed files with 307 additions and 150 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
* The WebSocket Integration infrastructure {@code beanFactory} initializer.
*
* @author Artem Bilan
* @author Gary Russell
* @since 4.1
*/
public class WebSocketIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
@@ -99,7 +100,7 @@ public class WebSocketIntegrationConfigurationInitializer implements Integration
BeanDefinitionBuilder enableWebSocketBuilder =
BeanDefinitionBuilder.genericBeanDefinition(WebSocketHandlerMappingFactoryBean.class)
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
.addConstructorArgReference("defaultSockJsTaskScheduler");
.addPropertyReference("sockJsTaskScheduler", "defaultSockJsTaskScheduler");
registry.registerBeanDefinition(WEB_SOCKET_HANDLER_MAPPING_BEAN_NAME,
enableWebSocketBuilder.getBeanDefinition());
@@ -110,11 +111,11 @@ public class WebSocketIntegrationConfigurationInitializer implements Integration
private static class WebSocketHandlerMappingFactoryBean extends AbstractFactoryBean<HandlerMapping>
implements ApplicationContextAware {
private final ServletWebSocketHandlerRegistry registry;
private ServletWebSocketHandlerRegistry registry;
private ApplicationContext applicationContext;
public WebSocketHandlerMappingFactoryBean(ThreadPoolTaskScheduler sockJsTaskScheduler) {
public void setSockJsTaskScheduler(ThreadPoolTaskScheduler sockJsTaskScheduler) {
this.registry = new ServletWebSocketHandlerRegistry(sockJsTaskScheduler);
}
@@ -139,6 +140,7 @@ public class WebSocketIntegrationConfigurationInitializer implements Integration
public Class<?> getObjectType() {
return HandlerMapping.class;
}
}
}