rspec/rules/S5673/java/rule.adoc

68 lines
1.3 KiB
Plaintext
Raw 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.

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
----
@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
----
@Service // Compliant
public class CustomerServiceImpl {
// ...
}
@Repository // Compliant
public class ProductRepository {
// ...
}
@RestController // Compliant
public class FooBarRestController {
// ...
}
@Component // Compliant
public class SomeOtherComponent {
// ...
}
----
== See
* 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)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]