Associate ResourceLoader with RabbitConnectionFactoryBean

Closes gh-22332
pull/23540/head
Stephane Nicoll 4 years ago
parent 36382e599c
commit cc1f7402a7

@ -44,6 +44,7 @@ import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.io.ResourceLoader;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for {@link RabbitTemplate}. * {@link EnableAutoConfiguration Auto-configuration} for {@link RabbitTemplate}.
@ -97,12 +98,11 @@ public class RabbitAutoConfiguration {
@Bean @Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties properties, public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties properties,
ObjectProvider<CredentialsProvider> credentialsProvider, ResourceLoader resourceLoader, ObjectProvider<CredentialsProvider> credentialsProvider,
ObjectProvider<CredentialsRefreshService> credentialsRefreshService, ObjectProvider<CredentialsRefreshService> credentialsRefreshService,
ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception { ObjectProvider<ConnectionNameStrategy> connectionNameStrategy) throws Exception {
CachingConnectionFactory factory = new CachingConnectionFactory( CachingConnectionFactory factory = new CachingConnectionFactory(getRabbitConnectionFactoryBean(properties,
getRabbitConnectionFactoryBean(properties, credentialsProvider, credentialsRefreshService) resourceLoader, credentialsProvider, credentialsRefreshService).getObject());
.getObject());
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get();
map.from(properties::determineAddresses).to(factory::setAddresses); map.from(properties::determineAddresses).to(factory::setAddresses);
map.from(properties::getAddressShuffleMode).whenNonNull().to(factory::setAddressShuffleMode); map.from(properties::getAddressShuffleMode).whenNonNull().to(factory::setAddressShuffleMode);
@ -120,9 +120,10 @@ public class RabbitAutoConfiguration {
} }
private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean(RabbitProperties properties, private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean(RabbitProperties properties,
ObjectProvider<CredentialsProvider> credentialsProvider, ResourceLoader resourceLoader, ObjectProvider<CredentialsProvider> credentialsProvider,
ObjectProvider<CredentialsRefreshService> credentialsRefreshService) throws Exception { ObjectProvider<CredentialsRefreshService> credentialsRefreshService) {
RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean(); RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
factory.setResourceLoader(resourceLoader);
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get();
map.from(properties::determineHost).whenNonNull().to(factory::setHost); map.from(properties::determineHost).whenNonNull().to(factory::setHost);
map.from(properties::determinePort).to(factory::setPort); map.from(properties::determinePort).to(factory::setPort);

Loading…
Cancel
Save