I have a small question. If the class is annotated with @Component, @Service, @Controller or @Repository and I want to inject its dependency, do I need @Autowired?
@RestController
@RequestMapping(value = "/goods", produces = APPLICATION_JSON_VALUE)
@SuppressWarnings("squid:S4684")
public class UserDeviceRestController implements UserDeviceRestApi {
private final UserDeviceService userDeviceService;
public UserDeviceRestController(UserDeviceService userDeviceService) {
this.userDeviceService = userDeviceService;
}
This code works perfect for me because it is @Service annotation specified in UserDeviceService. Is it because of that?
If I would have a class without one of this annotations (bolded), I assume I have to @Autowired it in constructor/field/setter then... So why not to specify @Component above all the possible dependency injected classes and do not remember about @Autowired
Thanks for hints