Inject service inside the src classes

Note: A service can be injected inside only those classes which are the Spring Beans.

This blog for injecting the service inside the src/groovy classes.

To inject the service we need to know about two spring Annotations
1) @Component: This annotation is use for register a class as Bean in Spring container
2) @Autowired: This Autowired annotation is use for the autowired the dependency.

Example:

Suppose we have a Util class in which we want to inject UserService

@Component
class Util {

   @Autowired
   UserService userService

    void show(){
        userService.getCurrentUser();
    }

}
class UserService {
def springSecurityService

    def getCurrentUser() {
     log.debug("Current Login User":
                springSecurityService.currentUser);
   }
}