@Controller// Defines that this class is a spring bean@RequestMapping("/users")publicclassSomeController {// Tells the application context to inject an instance of UserService here @AutowiredprivateUserService userService; @RequestMapping("/login")publicvoidlogin(@RequestParam("username") String username, @RequestParam("password") String password) {// The UserServiceImpl is already injected and you can use ituserService.login(username, password); }}
Contoh code tanpa @Autowired
@Controller// Defines that this class is a spring bean@RequestMapping("/users")publicclassSomeController {privateUserService userService;publicSomeController(UserService userService) {this.userService= userService; } @RequestMapping("/login")publicvoidlogin(@RequestParam("username") String username, @RequestParam("password") String password) {// The UserServiceImpl is already injected and you can use ituserService.login(username, password); }}
Override
Penjelasan @Override dapat disimak pada link berikut.