68 lines
1.3 KiB
Plaintext
68 lines
1.3 KiB
Plaintext
The Spring Framework provides several specializations of the generic ``++@Component++`` stereotype annotation which better express the programmer’s 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[]
|