Я новичок в Spring Boot. Я создал демонстрационный REST API в Spring Boot. В следующем коде, даже если удалить аннотацию @Autowired, контроллер все равно будет работать, и я смогу вызвать API.
Я новичок в Spring Boot. Я создал демонстрационный REST API в Spring Boot. В следующем коде, даже если удалить аннотацию @Autowired, контроллер все равно будет работать, и я смогу вызвать API. [code]import com.abhishek.demo2.entity.Question; import com.abhishek.demo2.service.QuestionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RequestMapping("/question") public class QuestionController { QuestionService questionService;
@Autowired public QuestionController(QuestionService questionService) { this.questionService = questionService; }
@GetMapping("/all") public List getAllQuestions() { return questionService.getAllQuestions(); } } [/code] Итак, теперь мне интересно, для чего нужна эта аннотация @Autowired и как она работает. Спасибо.