无法使用myBatis

时间:2019-04-05 18:25:06

标签: java sql xml eclipse spring-mybatis

我正在创建一个小的CRUD Web应用程序以显示课程,但是当我尝试运行它时,它会给我这个异常,并带有嵌套异常,

  

org.springframework.transaction.CannotCreateTransactionException:   无法打开JDBC连接进行事务;嵌套异常为   java.sql.SQLException:java.lang.ClassCastException:   java.math.BigInteger不能强制转换为java.lang.Long   org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)   org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)   org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)   org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)   org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)   com.sun.proxy。$ Proxy23.insertCourse(来源不明)   com.cyberx.signup.controller.CourseController.signup(CourseController.java:29)     sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)     sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)     sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)     java.lang.reflect.Method.invoke(未知源)   org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)   org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)     javax.servlet.http.HttpServlet.service(HttpServlet.java:621)     javax.servlet.http.HttpServlet.service(HttpServlet.java:728)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)   根本原因java.sql.SQLException:java.lang.ClassCastException:   无法将java.math.BigInteger强制转换为java.lang.Long

这是我对数据库的配置:

<beans:bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <beans:property name="url" value="jdbc:mysql://localhost:3306/courses" />
        <beans:property name="username" value="root" />
        <beans:property name="password" value="gr3288235517" />
    </beans:bean>
        <tx:annotation-driven transaction-manager="transactionManager" />
    <beans:bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <beans:property name="dataSource" ref="dataSource" />
    </beans:bean>
    <beans:bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="typeAliasesPackage" value="com.cyberx.signup.controller.model" />
        <beans:property name="mapperLocations"
            value="classpath*:com/cyberx/signup/mapper/*.xml" />
    </beans:bean>

0 个答案:

没有答案