rspec/rules/S5673/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

77 lines
1.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Why is this an issue?
The Spring Framework provides several specializations of the generic ``++@Component++`` stereotype annotation which better express the programmers intent. Using them should be preferred.
=== Noncompliant code example
[source,java]
----
@Component // Noncompliant; class name suggests it's a @Service
public class CustomerServiceImpl {
// ...
}
@Component // Noncompliant; class name suggests it's a @Repository
public class ProductRepository {
// ...
}
@Component // Noncompliant; class name suggests it's a @Controller or @RestController
public class FooBarRestController {
// ...
}
----
=== Compliant solution
[source,java]
----
@Service // Compliant
public class CustomerServiceImpl {
// ...
}
@Repository // Compliant
public class ProductRepository {
// ...
}
@RestController // Compliant
public class FooBarRestController {
// ...
}
@Component // Compliant
public class SomeOtherComponent {
// ...
}
----
== Resources
* https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-stereotype-annotations[Spring documentation - @Component and Further Stereotype Annotations]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use @<SpecializedAnnotation> instead of @Component
'''
== Comments And Links
(visible only on this page)
=== on 11 Dec 2019, 16:42:36 Tibor Blenessy wrote:
Based on community suggestion \https://community.sonarsource.com/t/use-specializations-of-component-for-specific-use-cases/12379
endif::env-github,rspecator-view[]