我正在使用Tomcat 8.5并创建一个列出学生的servlet。
由于我没有在依赖注入框架中工作,有没有办法
告诉servlet容器自动实例化studentService
?
此外,StudentService是一个具体的类而不是接口。
@WebServlet("/students")
public class StudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private StudentService studentService;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Student> students = studentService.list();
request.setAttribute("students", students);
request.getRequestDispatcher("/students.jsp").forward(request, response);
}
}