rspec/rules/S3750/java/rule.adoc

40 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Spring ``++@Controller++``s, ``++@Service++``s, and ``++@Repository++``s have ``++singleton++`` scope by default, meaning only one instance of the class is ever instantiated in the application. Defining any other scope for one of these class types will result in needless churn as new instances are created and destroyed. In a busy web application, this could cause a significant amount of needless additional load on the server.
This rule raises an issue when the ``++@Scope++`` annotation is applied to a ``++@Controller++``, ``++@Service++``, or ``++@Repository++`` with any value but "singleton". ``++@Scope("singleton")++`` is redundant, but ignored.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
@Scope("prototype") // Noncompliant
@Controller
public class HelloWorld {
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
@Controller
public class HelloWorld {
----
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[]