rspec/rules/S3438/xml/rule.adoc

54 lines
1.7 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Use of a Spring ``++SingleConnectionFactory++`` without enabling the ``++reconnectOnException++`` setting will prevent automatic connection recovery when the connection goes bad.
That's because the ``++reconnectOnException++`` property defaults to ``++false++``. As a result, even if the code that uses this connection factory (Spring's ``++DefaultMessageListenerContainer++`` or your own code) has reconnect logic, that code won't work because the ``++SingleConnectionFactory++`` will act like a single-connection pool by preventing connection ``++close++`` calls from actually closing anything. As a result, subsequent factory ``++create++`` operations will just hand back the original broken ``++Connection++``.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,xml]
2021-04-28 16:49:39 +02:00
----
<bean id="singleCF" class="org.springframework.jms.connection.SingleConnectionFactory"> <!-- Noncompliant -->
<constructor-arg ref="dummyConnectionFactory" />
</bean>
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,xml]
2021-04-28 16:49:39 +02:00
----
<bean id="singleCF" class="org.springframework.jms.connection.SingleConnectionFactory" p:reconnectOnException="true">
<constructor-arg ref="dummyConnectionFactory" />
</bean>
----
or
2022-02-04 17:28:24 +01:00
[source,xml]
2021-04-28 16:49:39 +02:00
----
<bean id="singleCF" class="org.springframework.jms.connection.SingleConnectionFactory">
<constructor-arg ref="dummyConnectionFactory" />
<property name="reconnectOnException"><value>true</value></property>
</bean>
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]