16
16
17
17
package org .springframework .boot .autoconfigure .jms .activemq ;
18
18
19
- import java .util .List ;
20
19
import java .util .stream .Collectors ;
21
20
22
21
import javax .jms .ConnectionFactory ;
49
48
class ActiveMQConnectionFactoryConfiguration {
50
49
51
50
@ Configuration
52
- @ ConditionalOnClass (CachingConnectionFactory .class )
53
51
@ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "false" ,
54
52
matchIfMissing = true )
55
53
static class SimpleConnectionFactoryConfiguration {
56
54
57
- private final JmsProperties jmsProperties ;
58
-
59
- private final ActiveMQProperties properties ;
60
-
61
- private final List <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ;
62
-
63
- SimpleConnectionFactoryConfiguration (JmsProperties jmsProperties , ActiveMQProperties properties ,
64
- ObjectProvider <ActiveMQConnectionFactoryCustomizer > connectionFactoryCustomizers ) {
65
- this .jmsProperties = jmsProperties ;
66
- this .properties = properties ;
67
- this .connectionFactoryCustomizers = connectionFactoryCustomizers .orderedStream ()
68
- .collect (Collectors .toList ());
55
+ @ Bean
56
+ @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "false" )
57
+ public ActiveMQConnectionFactory jmsConnectionFactory (ActiveMQProperties properties ,
58
+ ObjectProvider <ActiveMQConnectionFactoryCustomizer > factoryCustomizers ) {
59
+ return new ActiveMQConnectionFactoryFactory (properties ,
60
+ factoryCustomizers .orderedStream ().collect (Collectors .toList ()))
61
+ .createConnectionFactory (ActiveMQConnectionFactory .class );
69
62
}
70
63
71
- @ Bean
64
+ @ ConditionalOnClass ( CachingConnectionFactory . class )
72
65
@ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "true" ,
73
66
matchIfMissing = true )
74
- public CachingConnectionFactory cachingJmsConnectionFactory () {
75
- JmsProperties .Cache cacheProperties = this .jmsProperties .getCache ();
76
- CachingConnectionFactory connectionFactory = new CachingConnectionFactory (createConnectionFactory ());
77
- connectionFactory .setCacheConsumers (cacheProperties .isConsumers ());
78
- connectionFactory .setCacheProducers (cacheProperties .isProducers ());
79
- connectionFactory .setSessionCacheSize (cacheProperties .getSessionCacheSize ());
80
- return connectionFactory ;
81
- }
82
-
83
- @ Bean
84
- @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "false" )
85
- public ActiveMQConnectionFactory jmsConnectionFactory () {
86
- return createConnectionFactory ();
87
- }
67
+ static class CachingConnectionFactoryConfiguration {
68
+
69
+ @ Bean
70
+ @ ConditionalOnProperty (prefix = "spring.jms.cache" , name = "enabled" , havingValue = "true" ,
71
+ matchIfMissing = true )
72
+ public CachingConnectionFactory cachingJmsConnectionFactory (JmsProperties jmsProperties ,
73
+ ActiveMQProperties properties ,
74
+ ObjectProvider <ActiveMQConnectionFactoryCustomizer > factoryCustomizers ) {
75
+ JmsProperties .Cache cacheProperties = jmsProperties .getCache ();
76
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory (
77
+ new ActiveMQConnectionFactoryFactory (properties ,
78
+ factoryCustomizers .orderedStream ().collect (Collectors .toList ()))
79
+ .createConnectionFactory (ActiveMQConnectionFactory .class ));
80
+ connectionFactory .setCacheConsumers (cacheProperties .isConsumers ());
81
+ connectionFactory .setCacheProducers (cacheProperties .isProducers ());
82
+ connectionFactory .setSessionCacheSize (cacheProperties .getSessionCacheSize ());
83
+ return connectionFactory ;
84
+ }
88
85
89
- private ActiveMQConnectionFactory createConnectionFactory () {
90
- return new ActiveMQConnectionFactoryFactory (this .properties , this .connectionFactoryCustomizers )
91
- .createConnectionFactory (ActiveMQConnectionFactory .class );
92
86
}
93
87
94
88
}
@@ -98,8 +92,7 @@ private ActiveMQConnectionFactory createConnectionFactory() {
98
92
static class PooledConnectionFactoryConfiguration {
99
93
100
94
@ Bean (destroyMethod = "stop" )
101
- @ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "true" ,
102
- matchIfMissing = false )
95
+ @ ConditionalOnProperty (prefix = "spring.activemq.pool" , name = "enabled" , havingValue = "true" )
103
96
public JmsPoolConnectionFactory pooledJmsConnectionFactory (ActiveMQProperties properties ,
104
97
ObjectProvider <ActiveMQConnectionFactoryCustomizer > factoryCustomizers ) {
105
98
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory (properties ,
0 commit comments