From aeff262c2e1d95988e3f41e4d9d487e19db14b16 Mon Sep 17 00:00:00 2001 From: William <87509674+WilliamSESE@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:37:02 +0800 Subject: [PATCH] A better suggestion about the annotation usage Hi, I found that there may be some minor improvements about annotations in your code. A Spring bean in the service layer should be annotated using @service instead of @component annotation. @service annotation is a specialization of @component in service layer. By using a specialized annotation we hit two birds with one stone. First, they are treated as Spring bean, and second, you can put special behavior required by that layer. For better understanding and maintainability of a large application, @service is a better choice. --- .../io/pivotal/web/security/CustomCredentialsService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/springboottrades-web/src/main/java/io/pivotal/web/security/CustomCredentialsService.java b/springboottrades-web/src/main/java/io/pivotal/web/security/CustomCredentialsService.java index c8838ed..9837a94 100644 --- a/springboottrades-web/src/main/java/io/pivotal/web/security/CustomCredentialsService.java +++ b/springboottrades-web/src/main/java/io/pivotal/web/security/CustomCredentialsService.java @@ -14,9 +14,9 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; -@Component +@Service public class CustomCredentialsService implements UserDetailsService { private static final Logger logger = LoggerFactory.getLogger(CustomCredentialsService.class);