Skip to content

Commit 91bd658

Browse files
garyrussellartembilan
authored andcommitted
Configurable ResourceLoader for RabbitCFactoryBean
Resolves #1217
1 parent 0674a3b commit 91bd658

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
import org.springframework.amqp.rabbit.support.RabbitExceptionTranslator;
4343
import org.springframework.beans.factory.config.AbstractFactoryBean;
4444
import org.springframework.core.io.Resource;
45+
import org.springframework.core.io.ResourceLoader;
4546
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
4647
import org.springframework.lang.Nullable;
48+
import org.springframework.util.Assert;
4749
import org.springframework.util.StringUtils;
4850

4951
import com.rabbitmq.client.ConnectionFactory;
@@ -122,7 +124,7 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
122124

123125
private final Properties sslProperties = new Properties();
124126

125-
private final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
127+
private ResourceLoader resourceLoader = new PathMatchingResourcePatternResolver();
126128

127129
private boolean useSSL;
128130

@@ -695,6 +697,27 @@ public void setTrustStoreAlgorithm(String trustStoreAlgorithm) {
695697
this.trustStoreAlgorithm = trustStoreAlgorithm;
696698
}
697699

700+
/**
701+
* Get the resource loader; used to resolve the key store and trust store {@link Resource}s
702+
* to input streams.
703+
* @return the resource loader.
704+
* @since 2.3
705+
*/
706+
protected ResourceLoader getResourceLoader() {
707+
return this.resourceLoader;
708+
}
709+
710+
/**
711+
* Set the resource loader; used to resolve the key store and trust store {@link Resource}s
712+
* to input streams.
713+
* @param resourceLoader the resource loader.
714+
* @since 2.3
715+
*/
716+
public void setResourceLoader(ResourceLoader resourceLoader) {
717+
Assert.notNull(resourceLoader, "'resourceLoader' cannot be null");
718+
this.resourceLoader = resourceLoader;
719+
}
720+
698721
/**
699722
* Access the connection factory to set any other properties not supported by
700723
* this factory bean.
@@ -791,7 +814,7 @@ protected KeyManager[] configureKeyManagers() throws KeyStoreException, IOExcept
791814
KeyManager[] keyManagers = null;
792815
if (StringUtils.hasText(keyStoreName) || this.keyStoreResource != null) {
793816
Resource resource = this.keyStoreResource != null ? this.keyStoreResource
794-
: this.resolver.getResource(keyStoreName);
817+
: this.resourceLoader.getResource(keyStoreName);
795818
KeyStore ks = KeyStore.getInstance(storeType);
796819
ks.load(resource.getInputStream(), keyPassphrase);
797820
KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.keyStoreAlgorithm);
@@ -814,7 +837,7 @@ protected TrustManager[] configureTrustManagers()
814837
TrustManager[] trustManagers = null;
815838
if (StringUtils.hasText(trustStoreName) || this.trustStoreResource != null) {
816839
Resource resource = this.trustStoreResource != null ? this.trustStoreResource
817-
: this.resolver.getResource(trustStoreName);
840+
: this.resourceLoader.getResource(trustStoreName);
818841
KeyStore tks = KeyStore.getInstance(storeType);
819842
tks.load(resource.getInputStream(), trustPassphrase);
820843
TrustManagerFactory tmf = TrustManagerFactory.getInstance(this.trustStoreAlgorithm);

0 commit comments

Comments
 (0)