Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring Basics Using the MVC Architecture Fix a Controller

Which line is the problem?

The question is: Continuing the previous code challenge of writing a task management application, you've now run into a new problem while testing your application. Any URI you try (including / and /tasks/1) produces a 404 error. It appears that the Spring Framework is not capturing your URI mappings in the controller class given below. Fix the one-line mistake in the class below to restore your application's functionality.

I have had an attempt based on CategoryController, but I can't seem to think of a solution that is likely to be only one line, so I must be going about the problem wrong. Any help would be much appreciated.

Thank you very much!

com/teamtreehouse/todo/controller/TaskController.java
package com.teamtreehouse.todo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.ui.ModelMap;

import com.teamtreehouse.todo.repository.TaskRepository;
import com.teamtreehouse.todo.model.Task;

public class TaskController {
  @Autowired
  private TaskRepository taskRepository;

  @RequestMapping("/")
  public String home() {
    return "task_index";
  }

  @RequestMapping("/tasks/{id}")
  public String task(@PathVariable int id, ModelMap modelMap) {
    TaskRepository taskRepository = taskRepository.findById(id);
    modelMap.put("task",taskRepository.findById(id));
    return "task_detail";
  }
}

1 Answer

Isaiah Duncan
Isaiah Duncan
3,241 Points

First thing I noticed, you're missing your @Controller annotation above your class.

That was apparently all it was! Gosh. Thank you again!