官方不推荐字段注入的方式,如下图所示:
public class HelloController {
@Autowired
private UserService userService;
}
使用lombok注解:@RequiredArgsConstructor进行构造器注入,如下图所示:
@RequiredArgsConstructor
public class HelloController {
private final UserService userService;
}