简体   繁体   English

使用spring3的mybatis配置

[英]mybatis configuration with spring3

I am trying to configure mybatis with spring 3. I am getting the following error while building my project. 我正在尝试使用Spring 3配置mybatis。在构建项目时出现以下错误。

Error creating bean with name 'datasource' defined in ServletContext resource [/WEB-       INF/spring-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

My spring-servel.xml is 我的spring-servel.xml是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">


<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />


<context:component-scan
    base-package="com.mycom.mycontroller.controller" />

<mvc:resources mapping="/resources/**" location="/resources/" />


<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driver" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/mydatabase"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.mycom.mydatabase.db.mybatis.sqlmap" />
</bean> 

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>

Jar files. Jar文件。 I have added are 我添加了

commons-dbcp-1.4.jar
commons-pool-1.6.jar
mybatis-3.1.0.jar
mybatis-spring-1.1.1.jar
mysql-connector-java-5.1.18-bin.jar
org.springframework.transaction-3.1.1.RELEASE.jar
and other spring jars

Please let me know if you need anything for more clarification 如果您需要任何进一步的说明,请告诉我

Problem has nothing to do with myBatis. 问题与myBatis无关。

org.apache.commons.dbcp.BasicDataSource has not any "driver" property. org.apache.commons.dbcp.BasicDataSource没有任何“驱动程序”属性。 I think you should user driverClassName instead. 我认为您应该改为使用driverClassName

See doc . 请参阅doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM