Announcement Announcement Module
Collapse
No announcement yet.
Defined URL Not Recognized - Another Code Broken With 3.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defined URL Not Recognized - Another Code Broken With 3.1

    A controller defined as
    Code:
    @RequestMapping("/profiles/new")
    @SessionAttributes(types = Profile.class)
    public class RegistrationController {
    ...
    }
    And it is declared in a XML file as
    Code:
    	<bean class="com.abc.myapp.account.web.RegistrationController"
    		... />
    With the debug log level, the log file shows
    15:40:36,890 DEBUG BeanDefinitionParserDelegate:497: - Neither XML 'id' nor 'name' specified - using generated bean name [com.abc.myapp.account.web.RegistrationController#0]
    The request mapping URL "/profiles/new" doesn't show up with RequestMappingHandlerMapping however. When I enter the URL on a browser, I get
    Oops! This link appears to be broken.
    The above works for the 3.0. So, is it a bug or some new change in the 3.1?

  • #2
    The debug message has nothing to do with your problem. Post your configuration and not only your controller.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      The debug message has nothing to do with your problem. Post your configuration and not only your controller.
      The problem could be caused by either the controller isn't instanced by Spring or the controller is instanced but fail on the request mapping. The reason I turned up the log level is to find out which case it is. Related configuration:
      Code:
      ...
      <mvc:annotation-driven />
      ...
      <context:component-scan base-package="com.abc.myapp.account.web" />
      ...

      Comment


      • #4
        Please post the full configuration, also if what you post is true you have 2 instances of your controller (the one explicitly defined in xml and one picked up by the compnent-scan). If you turned up the logging you will also see the urls and detected controllers pass by (these are logged at info level, at least the url mapping).

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          Please post the full configuration, also if what you post is true you have 2 instances of your controller (the one explicitly defined in xml and one picked up by the compnent-scan). If you turned up the logging you will also see the urls and detected controllers pass by (these are logged at info level, at least the url mapping).
          Interesting! I thought only beans with a stereotype annotation in order to get registered in the Spring context. There are more log messages for this issue.
          09:35:31,906 DEBUG BeanNameUrlHandlerMapping:86: - Rejected bean name 'com.abc.myapp.account.web.RegistrationController# 0': no URL paths identified
          and later
          09:35:34,234 DEBUG DefaultListableBeanFactory:217: - Creating shared instance of singleton bean 'com.abc.myapp.account.web.RegistrationController# 0'
          09:35:34,234 DEBUG DefaultListableBeanFactory:430: - Creating instance of bean 'com.abc.myapp.account.web.RegistrationController# 0'
          The configuration files are big and there is not possible to post all of them here. Any special portion is interested?

          Comment


          • #6

            Interesting! I thought only beans with a stereotype annotation in order to get registered in the Spring context. There are more log messages for this issue.
            My fault, I assumed (I know never assume) that there was also an @Controller annotation on the controller... This annotation is however needed for the RequestMappingHandlerMapping to detect your controllers. If the annotation isn't present it is ignored, so if you want to use the new RequestMapping* stuff add the @Controller annotation else you have to do some manual configuration and add the old DefaultAnnotationHandlerMapping and the AnnotationMethodHandlerAdapter.

            Comment


            • #7
              Thanks Marten. Again, the code works for the 3.0 version. I know the requestmapping portion is reworked for the 3.1. And the new version is not 100 percent backward compatible to the 3.0 version based on my upgrading experience.

              For my code, I wonder whether I can change to annotation based configuration instead. The reason I had the controller configured in a XML file is that data from a property file needs to pass into it along with some string data for file paths and such.

              Comment


              • #8
                The RequestMapping* is NEW to 3.1 it isn't reworked it is brand new. In 2.5 and 3.0 only the DefaultAnnotationHandlerMapping and the AnnotationMethodHandlerAdapter existed. If you check the source for the RequestMappingHandlerMapping you will see that it will only detect @RequestMapping annotations in @Controller annotated beans, your controller isn't a @Controller and as such ignored.

                What I suggested you to do is basically revert to the 3.0 configuration instead of the new 3.1 stuff (either that or simply add @Controller to your class and your problem will also be fixed which is btw mandatory if you want to use the 3.1 MVC stuff).

                Comment


                • #9
                  In the 3.1 version, the portion of Spring MVC is reworked based on my reading. The 3.1 version introduces RequestMappingHandlerMapping (http://static.springsource.org/sprin...erMapping.html) where causes this problem , I believe.

                  I am working on upgrading the project to the 3.1 and try to fix any backward compatible problems raised, but not write any new code nor change configuration for the existing functioning code.

                  Comment


                  • #10
                    I give up... I gave the solution and there is no other then either change code or change configuration else revert back to 3.0... How on earth are you going to fix problems without changing code or configuration?! @RequestMapping without @Controller or Controller is in my opinion questionable. The new 3.1 implementations also enforce this...

                    Comment


                    • #11
                      As this point, I believe some configuration change needed to make it work. The problem is I don't know what changes need to make.

                      Comment


                      • #12
                        Maybe read my posts?!

                        Originally posted by Marten Deinum
                        if you want to use the new RequestMapping* stuff add the @Controller annotation else you have to do some manual configuration and add the old DefaultAnnotationHandlerMapping and the AnnotationMethodHandlerAdapter.

                        Comment

                        Working...
                        X