maven spring mvc中的参数类型不匹配错误

时间:2014-03-21 06:37:00

标签: java maven spring-mvc

大家好我想学习maven。我在spring mvc 3.1中有这个工作项目,我需要将它转换为maven 3.2.1。一切都运作良好,但在我将这个项目转换为maven后,我收到了这个错误。

java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:724)

我不知道什么是错的我甚至无法调试,因为控件甚至没有进入函数。这是我的代码

JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add New Movie Detail</title>
        <style>
            .detail{
                margin: 0 auto;
            }
            .detail td{
                width: 300px;
                border:1px solid #999999
            }
            .detail td input{
                width:300px;
            }
            .message{
                width:300px;
                margin:0 auto;
                background-color: #66ff66;
                text-align: center;
                padding:5px;
            }
            .errors{
                color:#ff3333
            }
        </style>
    </head>
    <body>
        <c:if test="${not empty msg }">
            <div class="message">
                <span class="message-text">${msg }</a>
            </div>
        </c:if>  
        <form:form method="POST" action="insertMovie.do" modelAttribute="newMovie">
            <table class="detail">
                <tr>
                    <td>
                        Movie Name:
                    </td>
                    <td>
                        <form:input path="movie_name"/>
                        <span class="errors">
                            <form:errors path="movie_name"/>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        Actor Name:
                    </td>
                    <td>
                        <form:input path="actor"/>
                        <span class="errors">
                            <form:errors path="actor"/>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        Actress Name:
                    </td>
                    <td>
                        <form:input path="actress"/>
                        <span class="errors">
                            <form:errors path="actress"/>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        Director Name:
                    </td>
                    <td>
                        <form:input path="director"/>
                        <span class="errors">
                            <form:errors path="director"/>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" value="Save"/>
                    </td>
                </tr>
            </table>
        </form:form>
        <table>
            <tr>
                <td>
                    <a href="./moviedetail.view">Go back to movie detail</a>
                </td>
            </tr>
        </table>

    </body>
</html>

控制器我只发布依赖

的功能
@RequestMapping(value = "/newmovie.view")
    public String insertNewMovie(@ModelAttribute("newMovie") Movie movie, ModelMap model) {
        model.put(BindingResult.MODEL_KEY_PREFIX + "newMovie",
                model.get("errors"));
        return "newmovie";
    }

    @RequestMapping(value = "/insertMovie.do", method = RequestMethod.POST)
    public String addNewMovie(@Valid @ModelAttribute("newMovie") Movie movie, BindingResult result, ModelMap model, RedirectAttributes redirectAttr) {
        System.out.println("Movie name " + movie.getMovie_name());
        if (result.hasErrors()) {
            redirectAttr.addFlashAttribute("errors", result);
            redirectAttr.addFlashAttribute("newMovie", movie);
            return "redirect:newmovie.view";
        }
        mdao.insertMovieDetail(movie);
        redirectAttr.addFlashAttribute("msg", "Your Data has been successfully entered");
        return "redirect:newmovie.view";
    }

pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.moveez</groupId>
    <artifactId>Moveez</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Moveez</name>
    <url>http://maven.apache.org</url>

    <properties>
        <spring.version>3.1.1.RELEASE</spring.version>
        <junit.version>4.11</junit.version>
        <jdk.version>1.7</jdk.version>
        <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency> 

        <!-- Hibernate validator -->
        <dependency>
            <groupId>org.ow2.util.bundles</groupId>
            <artifactId>hibernate-validator-4.3.1.Final</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>              
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>Moveez</finalName>
    </build>
</project>

我想再次提醒你,这个项目在没有maven的情况下工作正常。

0 个答案:

没有答案