Skip to content

Commit 5077b6c

Browse files
Jean DetoeufDave Syer
authored andcommitted
Added ActiveMqCredentials (optional)
Fixes gh-618
1 parent d119336 commit 5077b6c

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/ActiveMQProperties.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class ActiveMQProperties {
3232

3333
private boolean pooled = false;
3434

35+
private String user;
36+
37+
private String password;
38+
3539
// Will override brokerURL if inMemory is set to true
3640
public String getBrokerUrl() {
3741
if (this.inMemory) {
@@ -60,4 +64,20 @@ public void setPooled(boolean pooled) {
6064
this.pooled = pooled;
6165
}
6266

67+
public String getUser() {
68+
return this.user;
69+
}
70+
71+
public void setUser(String user) {
72+
this.user = user;
73+
}
74+
75+
public String getPassword() {
76+
return this.password;
77+
}
78+
79+
public void setPassword(String password) {
80+
this.password = password;
81+
}
82+
6383
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,26 @@ protected static class ActiveMQConnectionFactoryCreator {
6464

6565
@Bean
6666
public ConnectionFactory jmsConnectionFactory() {
67+
ConnectionFactory connectionFactory;
68+
if (this.config.getUser() != null && !"".equals(this.config.getUser())
69+
&& this.config.getPassword() != null
70+
&& !"".equals(this.config.getPassword())) {
71+
connectionFactory = new ActiveMQConnectionFactory(this.config.getUser(),
72+
this.config.getPassword(), this.config.getBrokerUrl());
73+
}
74+
else {
75+
connectionFactory = new ActiveMQConnectionFactory(
76+
this.config.getBrokerUrl());
77+
}
6778
if (this.config.isPooled()) {
6879
PooledConnectionFactory pool = new PooledConnectionFactory();
69-
pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config
70-
.getBrokerUrl()));
80+
pool.setConnectionFactory(connectionFactory);
7181
return pool;
7282
}
73-
return new ActiveMQConnectionFactory(this.config.getBrokerUrl());
83+
else {
84+
return connectionFactory;
85+
}
7486
}
75-
7687
}
7788

7889
}

0 commit comments

Comments
 (0)