rspec/rules/S5673/java/rule.adoc

72 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Service // Compliant
public class CustomerServiceImpl {
// ...
}
@Repository // Compliant
public class ProductRepository {
// ...
}
@RestController // Compliant
public class FooBarRestController {
// ...
}
@Component // Compliant
public class SomeOtherComponent {
// ...
}
----
== Resources
2021-04-28 16:49:39 +02:00
* 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[]