Announcement Announcement Module
Collapse
No announcement yet.
@RequestMapping using wildcards fails with a NoSuchRequestHandlingMethodException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestMapping using wildcards fails with a NoSuchRequestHandlingMethodException

    So I've got a PersonController
    Code:
    @Controller
    @RequestMapping("/person/**")
    public class PersonController {
        String dateFormat = "yyyy-MM-dd";
        protected Log log = LogFactory.getLog(this.getClass());
        @Autowired
        private PersonService personService;
        private Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    
        @RequestMapping(value = "person/{id}", method = RequestMethod.GET)
        public String show(@PathVariable("id") Long id, ModelMap modelMap) {
    
            Assert.notNull(id, "Identifier must be provided.");
            if(log.isDebugEnabled()) {
                log.debug("Showing person with id: " +id);
            }
            modelMap.addAttribute("person", personService.find(id));
            return "person/show";
        }
    
        @RequestMapping(value = "person", method = RequestMethod.GET)
        public String list(ModelMap modelMap) {
            if(log.isDebugEnabled()) {
                log.debug("Listing all persons");
            }
            modelMap.addAttribute("people", personService.findAll());
            return "person/list";
        }
     @RequestMapping(value = "person/{id}", method = RequestMethod.DELETE)
        public String delete(@PathVariable("id") Long id, ModelMap modelMap) {
            Assert.notNull(id, "Identifier must be provided.");
    
            try {
                personService.remove(personService.find(id));
            } catch (DataIntegrityViolationException dive) {
                modelMap.addAttribute("integrityViolation", "The person is connected to another domain object. <br/>" +
                        "Remove the person from this object and then try again");
            }
            return "redirect:/person";
        }
    
        @RequestMapping(value ="person/form", method = RequestMethod.GET)
        public String form(ModelMap modelMap) {
            if(log.isDebugEnabled()) {
                log.debug("Creating new Person");
            }
            modelMap.addAttribute("person", new Person());
            return "person/create";
        }
    
        @RequestMapping(value = "person", method = RequestMethod.POST)
        public String create(@ModelAttribute("person") Person person, BindingResult result) {
            Assert.notNull(person, "Person must be provided");
            for(ConstraintViolation<Person> constraint : validator.validate(person)) {
                result.rejectValue(constraint.getPropertyPath(), null, constraint.getMessage());
            }
            if(result.hasErrors()) {
                return "person/create";
            }
            personService.persist(person);
            return "redirect:/person/" +person.getId();
        }
    
        @RequestMapping(value = "person/{id}/form", method = RequestMethod.GET)
        public String updateForm(@PathVariable("id") Long id, ModelMap modelMap) {
            Assert.notNull(id, "Identifier must be provided.");
            modelMap.addAttribute("person", personService.find(id));
            return "person/update";
        }
    
        @RequestMapping(method = RequestMethod.PUT)
        public String update(@ModelAttribute("person") Person person, BindingResult result) {
            Assert.notNull(person, "Person must be provided.");
            for(ConstraintViolation<Person> constraint : validator.validate(person)) {
                result.rejectValue(constraint.getPropertyPath(), null, constraint.getMessage());
            }
            if(result.hasErrors()) {
                return "person/update";
            }
            personService.merge(person);
            return "redirect:/person/" +person.getId();
    
        }
    
        @InitBinder
    	public void initBinder(WebDataBinder binder, WebRequest request) {
    		binder.registerCustomEditor(Person.class, new PersonEditor(personService));
            binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat(dateFormat), false));
    	}
    With my servlet.xml
    Code:
     <context:component-scan base-package="com.isharelib.library" />
        <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                <props>
                    <prop key=".DataAccessException">dataAccessFailure</prop>
                    <prop key=".lang.Exception">uncaughtException</prop>
                </props>
            </property>
        </bean>
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
           <!-- Maps request paths to flows in the flowRegistry; e.g. a path of /wizard looks for a flow with id "wizard" -->
    
         <!-- Maps request paths to @Controller classes; e.g. a path of /person looks for a controller named PersonController -->
           <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
    
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
    This was working, then I wanted to add Spring Security to the mix. So I add the 3.0.0.M1 jar files to my local repo and add the dependency, I now have the security configured, but the mappings to /person/** seems to have gone away.

    I can still do @RequestMapping("/register") for a RegisterController and see the mapping working, but the PersonController throws the following error when requesting appname/person:
    [CODE]
    ** Root cause is: No matching handler method found for servlet request: path '/person', method 'GET', parameters map[[empty]] org.springframework.web.servlet.mvc.multiaction.No SuchRequestHandlingMethodException: No matching handler method found for servlet request: path '/person', method 'GET', parameters map[[empty]] at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter$ServletHandlerMethodRe solver.resolveHandlerMethod(AnnotationMethodHandle rAdapter.java:498) at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:349) at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:342)
    [CODE]

    Any suggestions as to where I go wrong? Been racking my brains trying to find the difference between this and what I've got successfully working from the http://stsmedia.net finance application

  • #2
    Did you happen to solve this in the meantime Chris?

    I am having the exact same problem.

    Comment


    • #3
      Afraid not Kees.

      Though it seems like the tutorial on STSmedia

      http://stsmedia.net/spring-finance-p...3-integration/

      have solved it to some extent, at least they managed to add SS 3 to the Spring 3 project without breaking the @RequestMapping annotations. Though not with the custom User and Role classes which I wanted.

      Personally, since this was a private project, I ended up switching the project to grails.

      Can definitely recommend the stsmedia tutorial though. That was my starting point when I started the project in Spring.

      Comment

      Working...
      X