In my Spring MVC app, all my RequestMapping
are getting mapped properly except one. I am unable to figure out why this is getting PageNotFound
error. For the method addSatisfaction
, I am getting PageNotFound - No mapping found for HTTP request with URI [/CCHPWeb/heart2heart/feedback/102/resolution/satisfaction] in DispatcherServlet with name 'dispatcher'
.
My Controller
:
@Controller
@RequestMapping("/heart2heart/feedback")
public class H2HFeedbackController {
private static final Logger logger = LoggerFactory.getLogger(H2HFeedbackController.class);
private final ActivitiService activitiService;
private final Heart2HeartService heart2heartService;
@Autowired
public H2HFeedbackController(ActivitiService activitiService, Heart2HeartService heart2heartService) {
super();
this.activitiService = activitiService;
this.heart2heartService = heart2heartService;
}
@RequestMapping(value = "/${feedbackId}/resolution/satisfaction", method = RequestMethod.GET)
public String getSatisfaction(@PathVariable int feedbackId, Model model) {
Feedback feedback = new Feedback();
feedback.setId(feedbackId);
try {
feedback = heart2heartService.getFeedbackById(feedback);
if (feedback.getId() == 0) {
model.addAttribute("error", "Feedback does not exist");
model.addAttribute("status", "404 - Not Found");
return "error";
}
model.addAttribute("feedback", feedback);
} catch (Exception e) {
logger.error("Exception :: ", e);
}
return "heart2heart/closeFeedback";
}
@RequestMapping(value = "/{feedbackId}", method = RequestMethod.GET)
public String viewFeedback(@PathVariable int feedbackId, Model model) {
Feedback feedback = new Feedback();
feedback.setId(feedbackId);
try {
feedback = heart2heartService.getFeedbackById(feedback);
if (feedback.getId() == 0) {
model.addAttribute("error", "Feedback does not exist");
model.addAttribute("status", "404 - Not Found");
return "error";
}
model.addAttribute("feedback", feedback);
} catch (Exception e) {
logger.error("Exception :: ", e);
}
return "heart2heart/feedbackView";
}
}
My WebApplicationInitializer
is:
public class SiteMain implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.register(MvcConfig.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
You don't need a $ here:
change it to
$
stands for 'End of String (or Line)' in regex. I don't think you really need it in your path mapping as it does not make sense for an integer feedbackId.