I want to hit the readTasks
method of my controller when navigating to the root of my web app. I have set a breakpoint in the method but I am not hitting it when debugging on the server. I am using Eclipse.
I nagivate to: http://localhost:8080/ToDoList/ and I see my index page but the controller method is not invoked.
My Controller:
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TaskController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public List<TaskEntity> readTasks()
{
TaskEntityDao tasks = new TaskEntityDaoImpl();
return tasks.getAllTasks();
}
}
My web.xml:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I believe I am missing some configuration to initialise the controller, but I am not sure how to go about it. Do I need a configuration file that contains initialisation of every single controller in my application?