Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC2: Issue with RequestMethod.GET differs from M2 [SPR-6378] #11045

Closed
spring-projects-issues opened this issue Nov 17, 2009 · 5 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 17, 2009

Ken Sipe opened SPR-6378 and commented

I have a demo for Spring 3 Web that I've been running for some time... the upgrade to RC2 broke the demo. The code is listed below. What we need is details on the order of requestmappings... I thought I saw that earlier this year in the forums, but I can't find it anymore. Can someone please provide the details on the order of requestmappings... thanks.

The code below (which worked before) now fails for a GET request against the list method or http://localhost:8080/mvc/book/list

I had specified the GET and POST for clarification before on the create methods... after some investigation, I discovered that if I remove the method = RequestMethod.GET on the create method that the app begins to work. So I can work around this. What behavior should be expected?

@Controller
public class BookController {

    @Autowired
    BookDAO dao;

    // http://localhost:8080/mvc/book/list
    @RequestMapping("list")
    public List<Book> list() {
        return dao.findAllBooks();
    }

    // http://localhost:8080/mvc/book/book?id=12
    @RequestMapping("book")
    public Book book(@RequestParam(required = true) Long id) {

        Book book = dao.getBook(id);
        return book;
    }

    @RequestMapping(method = RequestMethod.GET)
    public Book create() {
        return new Book();

    }

    // http://localhost:8080/mvc/book/create (POST)
    @RequestMapping(method = RequestMethod.POST)
    public String create(@ModelAttribute Book book, BindingResult results) {

        if (book == null)
            return null;

        dao.save(book);

        return "redirect:list";
    }
}

Affects: 3.0 RC2

Issue Links:

Referenced from: commits 89975c8

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Added formatting.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

I'm having a hard time duplicating this behavior.

Is there any additional info you can give me, like registered handlermappings and other stuff in your application context? It might be easiest to attach that context as a whole...

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Closing as Cannot Reproduce for now, might reopen later when we have more info.

@spring-projects-issues
Copy link
Collaborator Author

Ken Sipe commented

I'll include the web.xml and the spring-config.xml... if more information is needed I'll put the whole project up on github. It would still be nice to know the order of preference for different requestmappings.

springmvc-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <context:component-scan base-package="com.codementor" />


    <bean id="urlMapping" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp"/>


    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" />

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"  />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven />
    
</beans>

web.xml file

<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/mvc/*</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>
      jsp/index.jsp
    </welcome-file>
  </welcome-file-list>

</web-app>

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

The problem was the combination of ControllerClassNameHandlerMapping and @RequestMapping. This should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants