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`
This commit is contained in:
Artem Bilan
2015-12-17 18:05:31 -05:00
committed by Gary Russell
parent 2be12160e9
commit fec2a36f42
15 changed files with 310 additions and 149 deletions

View File

@@ -13,9 +13,9 @@
</bean>
<bean id="xmppConnection" class="org.springframework.integration.xmpp.config.XmppConnectionFactoryBean">
<constructor-arg>
<property name="connectionConfiguration">
<bean factory-bean="xmppConnectionConfigurationBuilder" factory-method="build"/>
</constructor-arg>
</property>
<property name="autoStartup" value="false"/>
</bean>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-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.
@@ -28,13 +28,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Artem Bilan
*/
public class XmppConnectionFactoryBeanTests {
@Test
public void testXmppConnectionFactoryBean() throws Exception {
XmppConnectionFactoryBean xmppConnectionFactoryBean =
new XmppConnectionFactoryBean(mock(XMPPTCPConnectionConfiguration.class));
XmppConnectionFactoryBean xmppConnectionFactoryBean = new XmppConnectionFactoryBean();
xmppConnectionFactoryBean.setConnectionConfiguration(mock(XMPPTCPConnectionConfiguration.class));
XMPPConnection connection = xmppConnectionFactoryBean.createInstance();
assertNotNull(connection);
}