0

Hi I am creating a spring mvc app. The spring context seems to be mapping the controller methods to wrong urls.

I've following controllers:

HelloWorldController

package com.springapp.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/hello") public class HelloWorldController { @RequestMapping(method = RequestMethod.GET) public ModelAndView helloWorld() { String message = "Hello World, Spring 3.0!"; return new ModelAndView("hello", "message", message); } } 

ContactsController

package com.springapp.controller; import com.springapp.form.Contact; import com.springapp.service.ContactService; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/contacts") public class ContactsController { @Autowired private ContactService contactService; @RequestMapping(method = RequestMethod.GET) public String listContacts(Model map) { map.addAttribute("contact", new Contact()); map.addAttribute("contactList", contactService.listContacts()); return "contact"; } @RequestMapping(value="{contactId}", method=RequestMethod.GET) public String showContact(@PathVariable("contactId") Integer contactId) { contactService.getContact(contactId); return "redirect:/contacts"; } @RequestMapping(value = "/add", method = RequestMethod.POST) public String addContact(@ModelAttribute("contact") Contact contact, BindingResult result) { contactService.addContact(contact); return "redirect:/contacts"; } @RequestMapping("/{contactId}/delete") public String deleteContact(@PathVariable("contactId") Integer contactId) { contactService.removeContact(contactId); return "redirect:/contacts"; } } 

However the spring context is mapping them as:

INFO: Mapped URL path [/contacts/new] onto handler 'contactsController' INFO: Mapped URL path [/contacts/new.*] onto handler 'contactsController' INFO: Mapped URL path [/contacts/new/] onto handler 'contactsController' INFO: Mapped URL path [/contacts/addContact] onto handler 'contactsController' INFO: Mapped URL path [/contacts/addContact.*] onto handler 'contactsController' INFO: Mapped URL path [/contacts/addContact/] onto handler 'contactsController' INFO: Mapped URL path [/contacts/delete/{contactId}] onto handler 'contactsController' INFO: Mapped URL path [/contacts/delete/{contactId}.*] onto handler 'contactsController' INFO: Mapped URL path [/contacts/delete/{contactId}/] onto handler 'contactsController' INFO: Mapped URL path [/hello] onto handler 'helloWorldController' INFO: Mapped URL path [/hello.*] onto handler 'helloWorldController' INFO: Mapped URL path [/hello/] onto handler 'helloWorldController' 

Where is it getting these new and addContact patterns? Also the mapping /contacts is missing.

3
  • The log in your question is very strange because it not matches mappings in your ContactsController. Are you sure you posted code and log from the same version? Commented Jul 2, 2012 at 9:40
  • @davioooh Incidentally I had a addContact mapping in the ContactsController earlier, which I later updated to just add. As you can see I've also changed the mapping for deleteContact but it is not taking effect. Commented Jul 2, 2012 at 9:55
  • Are you using Eclipse to develop/run your project? Commented Jul 2, 2012 at 9:56

1 Answer 1

1

Your problem could depend on mappings you had in a old version of your application. Try to update the deployed version in Tomcat.

If you are using Eclipse to run/debug your project try to clean/compile your projet and than to deploy the new version in Tomcat.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I am using Eclipse and deploying on Glassfish.
Try to delete the deployed version and publish the new one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.