rspec/rules/S3756/java/rule.adoc

50 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
A cleanly coded web application will have a clear separation of concerns, with business logic in the ``++@Service++`` layer, and communication with other systems in the data access layer.
To help enforce such a separation of concerns, this rule raises an issue when a ``++@Service++`` class has ``++RestTemplate++``, ``++JmsTemplate++``, ``++WebServiceTemplate++``, ``++JdbcTemplate++``, or ``++DataSource++`` member.
=== 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
----
@Service ("greetingmanager")
public class GreetingManagerImpl implements GreetingManager
{
@Autowired
DataSource ds; // Noncompliant
----
=== 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 ("greetingmanager")
public class GreetingManagerImpl implements GreetingManager
{
@Autowired
GreetingDao gdao; // DataSource and its use have been moved here
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Move this "xxTypexx" member and its use to a DAO class.
=== Highlighting
member declaration
endif::env-github,rspecator-view[]